G Nair wrote:1. Why cant we assign a super class object to sub class refrence ?
Take the following example:
- super class Animal
- sub classes Dog and Cat
You can use a cast to force the compiler to still accept it, but then you'll get a ClassCastException.
2. why its not necessary to have a same return type for overloaded methods and overriden methods ?
Overloaded methods are completely different methods that have only one thing in common - the name. Other than that there is (syntactically) nothing in common.
Overridden methods must have the same return type, or a narrower. This is called covariant return. Look it up.
3. when (compile/run time) is it getting decided that which overladed / overriden method has to be called and why ?
For overloaded methods the compiler decides which one to use. During runtime the JVM uses the actual instance to find out from which class the method should be called. This must be done during runtime because during compile time the type simply isn't known.
4. exact diffrent between compiler and interpreter and how do they work in the background ?
I'm sure you can find an answer if you
SearchFirst. Google and Wikipedia should be more than able to help you with this.
5. what is Java compiler ? compiler + interpreter ? or only interpreter ? need more clarification on this ?
The name says it all. The Java compiler is only a compiler. The JVM is an interpreter that also includes a JIT compiler. Again, Google or use our search for more info.