Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About overridden methods.

 
Narendra shah
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In chapter 2 of K & B book, 2 mins drill down following statement is written. Can any body explain with an example?

Object type (not the reference variable's type), determines which overridden
method is used at runtime.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it refers to such a case:

Object type(here, Dog) (not the reference variable's type, here Animal), determines which overridden method is used at runtime. Dog's eat method will be called.
 
Anoobkumar Padmanabhan
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Narendra shah,

Object type (not the reference variable's type), determines which overridden
method is used at runtime.

it is actually the definition for overriding. right? The method, which will be called is determined by the type of object at runtime, not by the refence used.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic