aspose file tools*
The moose likes Beginning Java and the fly likes Have doubt in Interface. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Have doubt in Interface." Watch "Have doubt in Interface." New topic
Author

Have doubt in Interface.

Praveen Kumar
Ranch Hand

Joined: Nov 06, 2006
Posts: 133
Hi All,

My question is on concept of Abstract class and interfaces.

At Abstract class , we can have abstract methods and concrete methods too(optional). Where as Interface has to have all abstract methods.

Here at abstract class itself we can have all abstract methods.... then what is need of having interface in java.

Please don't reminder me Java not supports Multiple Inheritance.

There is some concept is why really interfaces is introduced.

Please help.

Praveen.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

Originally posted by Praveen Kumar:

Please don't reminder me Java not supports Multiple Inheritance.


Well, OK, but then I can't tell you why Java has interfaces. You have to pick one or the other requirement here!


[Jess in Action][AskingGoodQuestions]
John Griffin
author
Greenhorn

Joined: Oct 24, 2008
Posts: 22
Praveen,

One thing that an Interface can do for you is provide a standard method signature for a callback by the compiler. For example, let's say that some library you are using provides some type of data and provides this data via a call to a Printable Interface that the library tells you to implement on any class where you want to print out the data.

Since it will just be calling the print method of the class and providing the data it has no idea of the implementation you provide. You can print to a file, to a socket, to a screen, anywhere. The point is that the application library just calls the method of the class implementing the interface without regrad to the implementation.

Hope this helps.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
I'm sure that does help, John, and welcome to JavaRanch

But think how much more we could help if we were allowed to say "mimics multiple inheritance."
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Ernest Friedman-Hill:

Well, OK, but then I can't tell you why Java has interfaces. You have to pick one or the other requirement here!


Mhh, I wonder wether just providing a pointer to a site that does it qualifies...

http://faq.javaranch.com/java/InterfaceVsAbstractClass


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
Don't get me started about those stupid light bulbs.
 
subject: Have doubt in Interface.
 
Similar Threads
Diff between Abstract Class and Interface
Class within Interface
why to go for interface
which senario we use abstract and interface in java
confused with interface....