Create two interfaces called as Flying and Living interfaces and implement multiple
inheritance on the class “Bird”
a. The Flying interface should have methods like speed() and getMaxFlyHeight().
The Living interface should have methods like getName(), getWeight() and
getHeight().
b. Create two different objects of the class Bird (Bird should implement multiple
inheritance)
Answers
@Override
public void fly() {
System.out.println("Plane flying in the sky" );
}
}
public class Bird implements IFly {
@Override
public void fly() {
System.out.println("The bird soars in the sky" );
}
}
public class Balloon implements IFly {
@Override
public void fly() {
System.out.println("Balloons fly to the sky" );
}
}
test
public class Test {
public static void main(String[] args) {
IFly plane = new Plane();
IFly bird = new Bird();
IFly balloon = new Balloon();
plane.fly();
bird.fly();
balloon.fly();
}
}
Answer:
@Override
public void fly() {
System.out.println("Plane flying in the sky" );
}
}
public class Bird implements IFly {
@Override
public void fly() {
System.out.println("The bird soars in the sky" );
}
}
public class Balloon implements IFly {
@Override
public void fly() {
System.out.println("Balloons fly to the sky" );
}
}
test
public class Test {
public static void main(String[] args) {
IFly plane = new Plane();
IFly bird = new Bird();
IFly balloon = new Balloon();
plane.fly();
bird.fly();
balloon.fly();
}
}
Explanation: