Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
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 Android Security Essentials Live Lessons this week in the Android 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: 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

fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11170

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?
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?