Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Java Inheritance

  Asked By: Oscar    Date: Jan 23    Category: Java    Views: 791
  

I would like to join u to doscuss the below topic.


As super classes provide Abstract methods only, then what is
the need of explicitely implementing another class( APART FROM THE
VERY COMMON USE OF...MULTIPLE INHERITANCE)

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Julia Flores     Answered On: Jan 23

The following statement is not true:

"As super  classes provide abstract  methods only"

Super classes  can include implementation code as well as abstract
methods. You may be referring to interfaces so I will respond as such.
Interfaces let you define a contract which the implementing  class is
guaranteed to implement. As an example, let's say there is an interface
Storable with a single method store() and two classes Person and
Product. If both Person and Product implement Storable then you can
have a method such as the save method below and both Person and Product
instances can be passed to this method.

public void save(Storable s) {
s.store();
}

In the method you could then call the Storable.store() method as shown
in the example above and each object can implement the store()
functionality in whatever manner it wants. This is just one of the many
uses of interfaces.

 
Didn't find what you were looking for? Find more on Java Inheritance Or get search suggestion and latest updates.




Tagged: