wood burning stoves*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes which draw() is called? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "which draw() is called?" Watch "which draw() is called?" New topic
Author

which draw() is called?

Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531


when the super class constructor is executed which draw method is called? I was expecting superclass's draw() to be called but that wasn't the case
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

I was expecting superclass's draw() to be called

Why would draw() in Shape class be called. The draw method in RoundShape class overrides the draw method of shape class so the call will be polymorphic...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
but draw() is being called from within the Shape constructor....
Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
Ankit is it because at run time the jvm decides which draw method to call based on the object?
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

ankur kothari wrote:Ankit is it because at run time the jvm decides which draw method to call based on the object?

Bang on target, that's right, the call will be decided based on the actual object
Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
Thanks a lot
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: which draw() is called?