File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Is Interface a class? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Is Interface a class?" Watch "Is Interface a class?" New topic
Author

Is Interface a class?

karthick sathya
Greenhorn

Joined: Dec 17, 2007
Posts: 1
hi ,

i have some basic idea about class ,abstract class and interface. but still i'm not sure about the interface concepts.

i know interface is to achieve multiple inheritence and cannot create instances .
it also has some properties like class like interface will also compile into .class file.
Balasubramanian Chandrasekaran
Ranch Hand

Joined: Nov 28, 2007
Posts: 215

Originally posted by karthick sathya:
hi ,

i have some basic idea about class ,abstract class and interface. but still i'm not sure about the interface concepts.

i know interface is to achieve multiple inheritence and cannot create instances .
it also has some properties like class like interface will also compile into .class file.


An interface is a list of methods that must be implemented. A class that implements an interface must define all those methods. The method signatures (prototypes) are listed in the interface. Interfaces may also define public static final "constants". An interface is essentially the same as an completely abstract class.
Michael Breuer
Greenhorn

Joined: Nov 18, 2007
Posts: 7
Just to make it more concrete
An interface is a list of methods that must be implemented. A class that implements an interface must define all those methods. The method signatures (prototypes) are listed in the interface. Interfaces may also define public static final "constants". An interface is essentially the same as an completely abstract class.


A class can implement an interface without defining its methods when it is an abstract class. So the first class which shall be instanciated has to implement all methods which are not yet implemented in any superclass.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10906
    
  12

an interface is an agreement that states what methods a concrete object must implement (or inherit an actual implementation). It is NOT a class, but you can sort of pretend that objects that implement a certain interface are objects of that type.

The idea is to make code more flexible. the code that RECEIVES the object can pretend it's an object of the interface type.

Let's use a Pet interface. I write my code to accept Pets. Originally, my vendor only sends me Dogs, Cats, and Birds, all of which implement a Pet interface. In a year, the vendor can now also start sending me Fish, Ferrets, and Snakes, again all of which implement the interface. My code doesn't need to be changes AT ALL, since I'm only dealing with Pets.

Similarly, the vendor wants to change their Dog class. they are going to completly change how the whole thing works. They can create a Canine class. As long at that new class implements the Pet interface, nothing needs to be changed.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

You might be interested in: Interface vs. Abstract Class.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is Interface a class?
 
Similar Threads
Interfvace VS Abstract class
interface
B&S: Adding methods to Data that are not in DBMain
Marker InterFace...
JLS 6.4.3 The Members of an Interface Type