Google News
logo
Java Interfaces
Interfaces
1. Interface is also one of the type of class it contains only abstract methods.
2. For the interfaces also .class files will be generated.
3. Each and every interface by default abstract hence it is not possible to create an object.
4. Interfaces not alternative for abstract class it is extension for abstract classes.
5. 100 % pure abstract class is called interface.
6. The Interface contains only abstract methods means unimplemented methods.
7. Interfaces giving the information about the functionalities it are not giving the information about internal implementation.
8. To provide implementation for abstract methods we have to take separate class that class we can called it as implementation class for that interface.
9. Interface can be implemented by using implements keyword.
10. For the interfaces also the inheritance concept is applicable.
Interface program
Interface it1 
{ 
Void m1(); 
Void m2(); 
Void m3(); 
} 
Class Test implements it1 
{ 
Public void m1() 
{ 
System.out.println(“m1-method implementation ”); 
} 
Public void m2() 
{ 
System.out.println(“m2-method implementation”); 
} 
Public void m3() 
{ 
System.out.println(“m3 –method implementation”);
} 
Public static void main(String[] args) 
{ 
Test t=new Test(); 
t.m1(); 
t.m2(); 
t.m3(); 
} 
}
Output :
output:m1-method implementation,,m2-method implementation,,m3 –method implementation
Partially implemented class
Interface it1 
{ 
Void m1(); 
Void m2(); 
Void m3(); 
} 
Abstract Class ImplClass implements it1 
{ 
Public void m1()
{
System.out.println("m1-method implementation" ); 
} 
} 
Class Test extends ImplClass 
{ 
Public void m2() 
{ 
System.out.println ("m2-method implementation"); 
}
Public void m3()
{
System.out.println ("method implementation"); 
} 
Public static void main(String[] args) 
{ 
Test t=new Test(); 
t.m1(); 
t.m2(); 
t.m3(); 
} 
}
Output :
output:m1-method implementation,,m2-method implementation,,m3-method implementation,,
Multiple inheritance
interface a{ 
int a=20; 
void hi(); 
} 
interface b{ 
int a=30; 
void hi(); 
} 
class sup implements a,b{ 

public void hi() { 
System.out.println(b.a); 
System.out.println("hi"); 

} 
public static void main(String...strings ){
sup s=new sup(); 
s.hi(); 
} 

}
Output :
output:30,,hi