Thursday 27 September 2012

Java Practical - 17



    Program Definition 17 ::
 
     Interface A declares a display() method.  Classes C1, C2 and C3 implement that method.  The main() method declares variable a of type A.  Therefore, it can hold a reference to any object of class C1, C2 and C3 and invoking the display() method relative to the interface reference.




interface A
{
public void display();
}

class C1 implements A
{
public void display()
{
System.out.println("C1 display called");
}
}
class C2 implements A
{
public void display()
{
System.out.println("C2 display called");
}

}
class C3 implements A
{
public void display()
{
System.out.println("C3 display called");
}

}

class Prog17
{
public static void main( String args[] )
{
C1 c1 = new C1();
C2 c2 = new C2();
C3 c3 = new C3();

c1.display();
c2.display();
c3.display();
}
}

/*
D:\JAVA >javac Prog17.java

D:\JAVA >java Prog17
C1 display called
C2 display called
C3 display called
*/

Kindly Bookmark and Share it:

0 comments :

Post a Comment

Any Query ? any suggestion ? comment here

 

Recent Post

Recent Comments

© 2010 IamLearningHere Template by MBT