class er
{
public static void main(String [] args)
{
b s = new b();
s.display(9,2);
}
}[/code]
1)is this method overloading ? There is a statement in java like method overloading has nothing to do with inheritance and polymorphism then why is this working here ?
2) can we say the method overloading as compile time polymorphism (static binding)and method overriding as run time polymorphism(late binding)?
3) can we use method overloading even in inheritance then?
There is a rule in overriding that arguments must be the same and return type must be compatible .
RULE 1-->whatever the superclass takes as an argument the subclass overriding the method must use the same argument
RULE 2 -- > Whatever the superclass declares as return type .the overriding method must declare either the same type or a subclass type .remember a subclass object is guaranteed to be able to do anything its superclass declares so its safe to return a subclass where the superclass is expected
4) return type must be compatible ? what does this mean ? is compatible = same ?
In rule 1 does same argument means same type ? or same variable name?
5) to illustrate rule 2 i wrote one program like this
here in subclass i have overridden the method by using same argument type but with different return type which subclass intends ? iam getting compile time error but rule 2 says (this only) as per my view )...Correct me if iam wrong ? rule 2 says remember a subclass object is guaranteed to be able to do anything its superclass declares so its safe to return a subclass where the superclass is expected
6)
here i cant override a public method and make it private .Actually the compiler thinks at compile time that it is a public method ..if suddenly at run time the jvm slammed the door shut because the overriding version called at run time is private . then why am i getting compile time error rather than run time error because the compiler should'nt bother the jvm has to bother as i suppose ?'
please let me know how can i know these issues like compiler considers some issues and jvm bothers about few ..how would i know that ? Does it come by practise or is there any way to know about that
7) During method overloading you can vary the access levels in any direction ..what does this mean ?
8) During method overloading if only the return type is different its not a valid overload- the compiler will assume you are trying to override the method and even that wont be legal unless the return type is a subtype of the return type declared in a super class . what does this mean ?
does that mean we can put any return type in our sublass to make it a legal ?