Interface Implementation an Interface defined in class
example here underpackage practice.test;
public class IntefaceInsideClass {
interface Viechle{
public int getNoOfWheels();
}
}
Implementation of Interface
package practice.test;
public class Bus implements IntefaceInsideClass.Viechle{
public int getNoOfWheels() {
return 6;
}
}
package practice.test;
public class Cars implements IntefaceInsideClass.Viechle{
public int getNoOfWheels() {
return 4;
}
}
package practice.test;
public class Bikes implements IntefaceInsideClass.Viechle{
public int getNoOfWheels() {
return 2;
}
}
Finaly call for executions
package practice.test;
public class TestClass1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Bus b = new Bus();
System.out.println("No of Wheels for bus\t"+b.getNoOfWheels());
Cars c=new Cars();
System.out.println("No of Wheels for cars\t"+c.getNoOfWheels());
Bikes b1=new Bikes();
System.out.println("No of Wheels for bike\t"+b1.getNoOfWheels());
}
}
Output
-------------
No of Wheels for bus 6
No of Wheels for cars 4
No of Wheels for bike 2
No comments:
Post a Comment