GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes superclass use a method of its subclass? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "superclass use a method of its subclass?" Watch "superclass use a method of its subclass?" New topic
Author

superclass use a method of its subclass?

sandy chauhan
Ranch Hand

Joined: Apr 14, 2013
Posts: 31
Can a Superclass use a method of its subclass if yes how.....?
Stuie Clarky
Ranch Hand

Joined: Nov 09, 2012
Posts: 73

Read about Java Inheritance, its fairly straightforward what the answer is though


OCAJP 7
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11356
    
  16

How would a superclass know which sub-class method to use? Or if there even is a sub-class?

I am assuming you are talking about creating an instance of the superclass, not simply using a super-class reference variable that it pointing to a subclass instance.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
GeeCON Prague 2014
 
subject: superclass use a method of its subclass?