File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Customer Requirements for Developers this week in the Jobs Discussion 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

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: 84

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

fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11817

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
I agree. Here's the link:
subject: superclass use a method of its subclass?
It's not a secret anymore!