• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

which draw() is called?

 
Ankur kothari
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Ankur kothari
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but draw() is being called from within the Shape constructor....
 
Ankur kothari
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ankit is it because at run time the jvm decides which draw method to call based on the object?
 
Ankit Garg
Sheriff
Posts: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic