CGR Unit2 Interfaces
CGR Unit2 Interfaces
• There can be only abstract methods in the Java interface, not method
body.
• By providing the interface keyword, Java allows you to fully utilize the
“one interface, multiple methods” aspect of polymorphism.
cgr 3
Interface
How to declare an interface?
interface <interface_name>{
cgr 5
Interface
cgr 6
Interface
cgr 7
Interface
cgr 8
Interface
interface Drawable{
void draw();
}
class TestInterface1{
public static void main(String args[]){
Drawable d=new Circle();
getDrawable()
d.draw();
}} cgr 9
Interface
cgr 10
Interface
interface Printable{
void print();
}
interface Showable{
void show();
}
class A7 implements Printable,Showable{
public void print(){System.out.println("Hello");}
public void show(){System.out.println("Welcome");}