** SCJP 5.0 84% **
** SCWCD 1.5 76% **
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
Life is easy because we write the source code.....
Mohamed Sanaulla wrote:Your reference type is of Base class. So it would invoke the Base class method.
** SCJP 5.0 84% **
** SCWCD 1.5 76% **
Chrix Wu wrote:
Mohamed Sanaulla wrote:Your reference type is of Base class. So it would invoke the Base class method.
what about dynamic binding, in runtime, the app should execuete the acutal object (not reference object)'s method, which is 'public f()'
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
Mohamed Sanaulla wrote:
Chrix Wu wrote:
Mohamed Sanaulla wrote:Your reference type is of Base class. So it would invoke the Base class method.
what about dynamic binding, in runtime, the app should execuete the acutal object (not reference object)'s method, which is 'public f()'
But that is only when the method is being overridden. In this case the f() in the Derived class is some method totally not related to the one in Base class.
** SCJP 5.0 84% **
** SCWCD 1.5 76% **
Chrix Wu wrote:no overriding -> no dynamic binding -> only calls the reference type's method rather than the actual object's method
correct?
Seetharaman Venkatasamy wrote:private methods are final automatically
Jesper de Jong wrote:
Chrix Wu wrote:no overriding -> no dynamic binding -> only calls the reference type's method rather than the actual object's method
correct?
Yes. Private methods cannot be overridden.
Try making the private method f() in the superclass protected and see what happens.
Jesper de Jong wrote:
Chrix Wu wrote:no overriding -> no dynamic binding -> only calls the reference type's method rather than the actual object's method
correct?
Yes. Private methods cannot be overridden.
Try making the private method f() in the superclass protected and see what happens.
munjal upadhyay wrote:
Jesper de Jong wrote:Try making the private method f() in the superclass protected and see what happens.
How can CLASS be PROTECTED ??
class can be only default or public ...
munjal upadhyay wrote:How can CLASS be PROTECTED ??
class can be only default or public ...
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.