Implicit conversions are automatically performed when a value is copied to a compatible type. For example:
Here, the value of a is promoted from short to int without the need of any explicit operator. This is known as astandard conversion. Standard conversions affect fundamental data types, and allow the conversions between numerical types (short to int, int to float, double to int...), to or from bool, and some pointer conversions. Converting to int from some smaller integer type, or to double from float is known as promotion, and is guaranteed to produce the exact same value in the destination type. Other conversions between arithmetic types may not always be able to represent the same value exactly:
If a negative integer value is converted to an unsigned type, the resulting value corresponds to its 2's complement bitwise representation (i.e., -1 becomes the largest value representable by the type, -2 the second largest, ...). The conversions from/to bool consider false equivalent to zero (for numeric types) and to null pointer (for pointer types); true is equivalent to all other values and is converted to the equivalent of 1. If the conversion is from a floating-point type to an integer type, the value is truncated (the decimal part is removed). If the result lies outside the range of representable values by the type, the conversion causesundefined behavior. Otherwise, if the conversion is between numeric types of the same kind (integer-to-integer or floating-to-floating), the conversion is valid, but the value is implementation-specific (and may not be portable).
Some of these conversions may imply a loss of precision, which the compiler can signal with a warning. This warning can be avoided with an explicit conversion. For non-fundamental types, arrays and functions implicitly convert to pointers, and pointers in general allow the following conversions:
Null pointers can be converted to pointers of any type Pointers to any type can be converted to void pointers. Pointer upcast: pointers to a derived class can be converted to a pointer of an accessible and unambiguousbase class, without modifying its const or volatile qualification.
2. At compilation time Java Source code converts into byte code .The interpreter execute this byte code at run time and gives output .Java is interpreted for the most part and hence platform independent. C++ run and compile using compiler which converts source code into machine level languages so c++ is plate from dependents 3. Java is platform independent language but c++ is depends upon operating system machine etc. C++ source can be platform independent (and can work on a lot more, especially embedeed, platforms), although the generated objects are generally platofrom dependent but there is clang for llvmwhich doesn't have this restriction. 4. Java uses compiler and interpreter both and in c++ their is only compiler 5. C++ supports operator overloading multiple inheritance but java does not. 6. C++ is more nearer to hardware then Java 7. Everything (except fundamental types) is an object in Java (Single root hierarchy as everything gets derived from java.lang.Object). 8. Java does is a similar to C++ but not have all the complicated aspects of C++ (ex: Pointers, templates, unions, operator overloading, structures etc..) Java does not support conditional compile (#ifdef/#ifndef type). 9. Thread support is built-in Java but not in C++. C++11, the most recent iteration of the C++ programming language does have Thread support though. 10. Internet support is built-in Java but not in C++. However c++ has support for socket programming which can be used. 11. Java does not support header file, include library files just like C++ .Java use import to include different Classes and methods. 12. Java does not support default arguments like C++. 13. There is no scope resolution operator :: in Java. It has . using which we can qualify classes with the namespace they came from. 14. There is no goto statement in Java. 15. Exception and Auto Garbage Collector handling in Java is different because there are no destructors into Java. 16. Java has method overloading, but no operator overloading just like c++. 17. The String class does use the + and += operators to concatenate strings and String expressions use automatic type conversion, 18. Java is pass-by-value. 19. Java does not support unsigned integer.
superClass2.someMethod(); // SubClass version is called .... Here, we see that even though both the object references superClass1 andsuperClass2 are of type 'SuperClass' only, but at run time they refer to the objects of types 'SuperClass' and 'SubClass' respectively. Hence, at compile time the compiler can't be sure if the call to the method 'someMethod()' on these references actually refer to which version of the method - the super class version or the sub class version. Thus, we see that dynamic binding in Java simply binds the method calls (inherited methods only as they can be overriden in a sub class and hence compiler may not be sure of which version of the method to call) based on the actual object type and not on the declared type of the object reference. Static Binding or Early Binding If the compiler can resolve the binding at the compile time only then such a binding is called Static Binding or Early Binding. All the instance method calls are always resolved at runtime, but all the static method calls are resolved at compile time itself and hence we have static binding for static method calls. Because static methods are class methods and hence they can be accessed using the class name itself (in fact they are encourgaed to be used using their corresponding class names only and not by using the object references) and therefore access to them is required to be resolved during compile time only using the compile time type information. That's the reason why static methods can not actually be overriden. Read more - Can you override static methods in Java? Similarly, access to all the member variables in Java follows static binding as Java doesn't support (in fact, it discourages) polymorphic behavior of member variables. For example:class SuperClass{ ... public String someVariable = "Some Variable in SuperClass"; ... } class SubClass extends SuperClass{ ... public String someVariable = "Some Variable in SubClass"; ... } ... ... SuperClass superClass1 = new SuperClass(); SuperClass superClass2 = new SubClass(); System.out.println(superClass1.someVariable); System.out.println(superClass2.someVariable);