| 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: 9948
|
|
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.
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
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
|
 |
 |
|
|
subject: Is Interface a class?
|
|
|