关于java和c++中布尔量的比较
2013-08-10 16:27
260 查看
在c++中允许 bool 量和 int 整形常量相互转换,并且用cout<<true; 在控制台上可以输出为 1
输出的结果为 0 1 1 1
在Java中不允许 boolean 和 int 整形量直接的转换,如果强制转换,如果相互转换编译器会提示错误。
输出结果为 true
此外,如果一个函数被 final 修饰,那么此函数不能被子类修改,但是子类可以调用
int main(int argc, _TCHAR* argv[]) { int num = 0; int total = 2; bool isBool = true; cout<<"Hello \tWorld"<<endl; /*printf("%s", "ddd");*/ //cin>>num; //cout<<num; cout<<"num is bool:"<<(bool) num<<endl; cout<<"total is bool:"<<(bool) total<<endl; cout<<"isBool is bool:"<<(int)isBool<<endl; cout<<"isBool is bool:"<<isBool<<endl; cin.get(); //cin.get(); return 0; }
输出的结果为 0 1 1 1
在Java中不允许 boolean 和 int 整形量直接的转换,如果强制转换,如果相互转换编译器会提示错误。
public class Test3 { public static final int a = 3; static int c = 0; int b = 1; boolean isBool = true; /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Test3 t3 = new Test3(); System.out.println(t3.isBool); // System.out.println((boolean)t3.c); // 提示错误 // System.out.println((int)t3.isBool); // 提示错误 } }
输出结果为 true
此外,如果一个函数被 final 修饰,那么此函数不能被子类修改,但是子类可以调用
相关文章推荐
- 关于java和c++中布尔量的比较
- 【Java】关于Java中参数传递方式与C++的比较
- JAVA关于Stirng,StringBuilder,StringBuffer的比较
- C\C++\Java字符串拼接比较
- 关于.Net与J2EE的比较,到底用微软平台还是Java平台的问题
- Java与C++编译过程比较
- 对象创建:Java和C++比较
- c++与java在嵌套类方面的比较
- JAVA 的interface观念 与C++ 多重继承的比较
- C++ JAVA的比较学:布尔量
- Java 中的泛型与 C++ 模板的比较
- 33_面向对象_06_虚拟机内存管理_垃圾回收机制_C++和java的比较
- Java和c/c++比较
- C++与Java比较
- 多态在 Java 和 C++ 编程语言中的实现比较
- priority_queue sort 自定义比较终极模板 C++ & JAVA
- java与C++一些比较
- C++与Java比较
- java关于null的介绍及比较问题..未完待续
- C++和Java中关于继承的点点滴滴