File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Class Inheritance and Interface Inheritance

 
Anjaneya Ram
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the difference between Class inheritance and interface inheritance.Please provide an example. Thanks in Advance.

Ram.
 
Ajith Kallambella
Sheriff
Posts: 5782
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Java in General(beginner) forum...
 
Layne Lund
Ranch Hand
Posts: 3061
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as I know, there isn't a difference except the differences that exist between classes and interfaces themselves.
 
Jason Fox
Ranch Hand
Posts: 114
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's simple, actually. First, when you inherit from a superclass, you automatically inherit all of its methods (except in the case of an abstract class) and have all of the default implementation. For example, when extend Applet, you get methods like add() and repaint() which are immediately usable by you with no coding. When you impliment an interface, you are saying basically 'I promise to implement all of the necessary methods in order for anyone to use this class as a <INTERFACE>. For example, when you implement Runnable, you must write a method called run() with the signature public void run(), because you are saying that the class (or object) is Runnable, so anyone using it can use the run() method. Its designed so that everyone is always on the same page, every Runnable object has a run() method, every ActionListener has an actionPerformed(ActionEvent) method, etc. Helps clear up confusion.
Jason
 
Lalit K Kumar
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
whenever you inherit from a class you get all the methods of superclass automatically inherited. you can apply your own implementation if you wish (but it is'nt necessary)
if you inherit from an interface you are bound to implement all the methods contained in the interface,
[ February 20, 2004: Message edited by: Lalit K Kumar ]
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic