SCJP 5.0
Good luck!!
A small leak can sink a Gigantic ship.>
Raj Kumar Bindal wrote:I really doubt if polymorphism is applied before instance creation.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Basically, polymorphism applies -- even before instantiation of the object has completed. Since the derived class overridden the base printme() method, it is always called.
YogeshS Pandit wrote:Greetings all. I've just joined coderanch and this is my first post. This is a good topic to understand polymorphism. But correct me if I am wrong, isn't it a bad idea to call overridable instance methods from a constructor, because of the reason mentioned by Henry?
Basically, polymorphism applies -- even before instantiation of the object has completed. Since the derived class overridden the base printme() method, it is always called.
As the overridden method in derived class can use an uninitialized instance variable.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Was that before people realised what a bad idea it is to call methods from constructors?Rob Prime wrote: . . . Note that Sun ignores both advices. They call several methods in constructors (for example setModel in several Swing components) without mentioning this.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie wrote:
Was that before people realised what a bad idea it is to call methods from constructors?Rob Prime wrote: . . . Note that Sun ignores both advices. They call several methods in constructors (for example setModel in several Swing components) without mentioning this.
Neil Cartmell wrote: It's a bad idea to call methods from constructors?
Seetharaman Venkatasamy wrote:
Neil Cartmell wrote: It's a bad idea to call methods from constructors?
the method *which is designed for overriding* by subclass . otherwise, there is no harm to call a method[say static method] from constructor
Neil Cartmell wrote:ok thanks!
Disagree. Probably best only to call private or final instance methods from a constructor.Seetharaman Venkatasamy wrote: . . . there is no harm to call a method[say static method] from constructor