Sukhitha sunil wrote:usually when we use ref variable of baseclass to access an obj of derived class, we only get d access to baseclass members
Sukhitha sunil wrote:usually when we use ref variable of baseclass to access an obj of derived class, we only get d access to baseclass members ,,but when i run this code ani.sleep() gives he output of derived class bird method ..please help me guys..to understand what is happening here
Ganesh Patekar wrote:When derived class defines an instance method having same signature with same access modifier and return type already defined in base class then that method is overriden by derived class.
Sukhitha sunil wrote:usually when we use ref variable of baseclass to access an obj of derived class, we only get d access to baseclass members
but when i run this code ani.sleep() gives he output of derived class bird method
Roel wrote:There is a massive difference between "which methods can be accessed" and "which methods will be executed". The first is decided at compile time, the latter is decided at runtime.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:All instance methods in Java are "virtual" by default.
Enthuware - Best Mock Exams and Questions for Oracle Java Certifications
Quality Guaranteed - Pass or Full Refund!
Roel De Nijs wrote:For a valid override, the access modifier for an overriding method can allow more, but not less, access than the overridden method.
I really had no notion about covariant return type, new thing learned. That link was much much helpful and mostly the explanation of last post of your's was in detail, learned a lot.The return type of the overriding method can be a subclass of the return type of the overridden method (= covariant return type)
Ganesh Patekar wrote:Edited: I adore the way you test whether somebody really understood or not by your famous pop quizzes hahaha just great
![]()