hansika motwani wrote:
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?
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?
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
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 ?
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)?
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) 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 ?
SCJP 6
SCJP 6
Punit Singh wrote:Good Job Sachin, really answering long question takes too much time.
SCJP 6
They weren't very bright, but they were very, very big. Ad contrast:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|