Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Is Interface a class?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
lowercase baba
Posts: 13019
66
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might be interested in: Interface vs. Abstract Class.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic