Interface Example
package mypackage;
public interface FirstInterface {
public int add (int a, int b);
}
package mypackage;public class FirstClass implements FirstInterface { public int add(int a, int b) {
int c =0;
c=a+b;
return c;
}}
package mypackage;public class SecondClass {
SecondClass(){
FirstClass a = new FirstClass();
}
public void add(){
FirstInterface a1=(FirstInterface)a;
int d =a1.add(10, 20);
System.out.println(""+d);
}
public static void main (String args[])
{
SecondClass sc = new SecondClass();
sc.add();
System.out.println();
}
FirstClass a = new FirstClass();
}
package mypackage;
public interface FirstInterface {
public int add (int a, int b);
}
package mypackage;public class FirstClass implements FirstInterface { public int add(int a, int b) {
int c =0;
c=a+b;
return c;
}}
package mypackage;public class SecondClass {
SecondClass(){
FirstClass a = new FirstClass();
}
public void add(){
FirstInterface a1=(FirstInterface)a;
int d =a1.add(10, 20);
System.out.println(""+d);
}
public static void main (String args[])
{
SecondClass sc = new SecondClass();
sc.add();
System.out.println();
}
FirstClass a = new FirstClass();
}
No comments:
Post a Comment