Main Class:
package interface_1;
public class Interface_1
{
public static void main(String[] args) {
Flyable f = new Bird();
f.fly();
((Bird)f).eat();
System.out.println("Bird need Fuel: "+ f.needFuel());
}
}
Interface Class:
package interface_1;
public class Interface_1
{
public static void main(String[] args) {
Flyable f = new Bird();
f.fly();
((Bird)f).eat();
System.out.println("Bird need Fuel: "+ f.needFuel());
}
}
Bird Class:
package interface_1;
public class Bird implements Flyable
{
@Override
public void fly()
{
System.out.println("Birds Fly in the "+Flyable.media);
}
@Override
public boolean needFuel()
{
return false;
}
public void eat()
{
System.out.println("Birds Eat");
}
}
Output
Birds Fly in the sky
Birds Eat
Bird need Fuel: false
Add your comment