Skip to main content
deleted 45 characters in body
Source Link
Ketan G
  • 517
  • 1
  • 5
  • 22

An interface in java is a blueprint of a class. It has static constants and abstract methods only.The interface in java is a mechanism to achieve fully abstraction. There can be only abstract methods in the java interface not method body. It is used to achieve fully abstraction and multiple inheritance in Java. An interface is a collection of abstract methods. A class implements an interface, thereby inheriting the abstract methods of the interface. An interface is not a class. Writing an interface is similar to writing a class, but they are two different concepts. A class describes the attributes and behaviors of an object. An interface contains behaviors(Abstract Methods) that a class implements. Unless the class that implements the interface is abstract, all the methods of the interface need to be defined in the class.Since multiple inheritance is not allowed in java so interface is only way to implement multiple inheritance. Here is an example for understanding interface

interface Printable{  
void print();  
}  
  
interface Showable{  
void print();  
}  
  
class testinterface1 implements Printable,Showable{  
  
public void print(){System.out.println("Hello");}  
  
public static void main(String args[]){  
testinterface1 obj = new testinterface1();  
obj.print();  
 }  
}

For more, visit http://javabykg.blogspot.in

An interface in java is a blueprint of a class. It has static constants and abstract methods only.The interface in java is a mechanism to achieve fully abstraction. There can be only abstract methods in the java interface not method body. It is used to achieve fully abstraction and multiple inheritance in Java. An interface is a collection of abstract methods. A class implements an interface, thereby inheriting the abstract methods of the interface. An interface is not a class. Writing an interface is similar to writing a class, but they are two different concepts. A class describes the attributes and behaviors of an object. An interface contains behaviors(Abstract Methods) that a class implements. Unless the class that implements the interface is abstract, all the methods of the interface need to be defined in the class.Since multiple inheritance is not allowed in java so interface is only way to implement multiple inheritance. Here is an example for understanding interface

interface Printable{  
void print();  
}  
  
interface Showable{  
void print();  
}  
  
class testinterface1 implements Printable,Showable{  
  
public void print(){System.out.println("Hello");}  
  
public static void main(String args[]){  
testinterface1 obj = new testinterface1();  
obj.print();  
 }  
}

For more, visit http://javabykg.blogspot.in

An interface in java is a blueprint of a class. It has static constants and abstract methods only.The interface in java is a mechanism to achieve fully abstraction. There can be only abstract methods in the java interface not method body. It is used to achieve fully abstraction and multiple inheritance in Java. An interface is a collection of abstract methods. A class implements an interface, thereby inheriting the abstract methods of the interface. An interface is not a class. Writing an interface is similar to writing a class, but they are two different concepts. A class describes the attributes and behaviors of an object. An interface contains behaviors(Abstract Methods) that a class implements. Unless the class that implements the interface is abstract, all the methods of the interface need to be defined in the class.Since multiple inheritance is not allowed in java so interface is only way to implement multiple inheritance. Here is an example for understanding interface

interface Printable{  
void print();  
}  
  
interface Showable{  
void print();  
}  
  
class testinterface1 implements Printable,Showable{  
  
public void print(){System.out.println("Hello");}  
  
public static void main(String args[]){  
testinterface1 obj = new testinterface1();  
obj.print();  
 }  
}
Source Link
Ketan G
  • 517
  • 1
  • 5
  • 22

An interface in java is a blueprint of a class. It has static constants and abstract methods only.The interface in java is a mechanism to achieve fully abstraction. There can be only abstract methods in the java interface not method body. It is used to achieve fully abstraction and multiple inheritance in Java. An interface is a collection of abstract methods. A class implements an interface, thereby inheriting the abstract methods of the interface. An interface is not a class. Writing an interface is similar to writing a class, but they are two different concepts. A class describes the attributes and behaviors of an object. An interface contains behaviors(Abstract Methods) that a class implements. Unless the class that implements the interface is abstract, all the methods of the interface need to be defined in the class.Since multiple inheritance is not allowed in java so interface is only way to implement multiple inheritance. Here is an example for understanding interface

interface Printable{  
void print();  
}  
  
interface Showable{  
void print();  
}  
  
class testinterface1 implements Printable,Showable{  
  
public void print(){System.out.println("Hello");}  
  
public static void main(String args[]){  
testinterface1 obj = new testinterface1();  
obj.print();  
 }  
}

For more, visit http://javabykg.blogspot.in

Post Made Community Wiki by Ketan G