This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 30
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: 11153
    
  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
 
wood burning stoves
 
subject: superclass use a method of its subclass?
 
Similar Threads
Doubt in assigning super class and subclass variables
Why we got warning when calling a static method through an instance?
overriding question
initialization sequence
how can we access a method from sub class from its super class?