(Abstract class, Interface, Method Overriding)Write a java program with proper
illustration to implement the following instructions:
a) Create an interface named Animals which declare a void method callSound() and a
int method run().
b) Create an abstract class Feline that implements Animals, then override the
callSound() method and print “roar”.
c) Create an abstract class Canine that implements Animals, then override the
callSound() method and print “how1”.
d) Create a class Lion that extends Feline, then override the callSound() method and
refer immediate parent class callSound() method , also override the run() method and
return 40.
public interface Animals {
void callSound();
int run();
}
public abstract class Feline implements Animals{
@Override
public void callSound() {
System.out.println("roar");
}
}
public abstract class Canine implements Animals{
@Override
public void callSound() {
System.out.println("howl");
}
}
public class Lion extends Feline{
@Override
public void callSound() {
super.callSound();
}
@Override
public int run() {
return 40;
}
}
Comments
Leave a comment