package abstractclassdemo;
public abstract class Animal {
public abstract void makesound();
}
*******************
package abstractclassdemo;
public class sheep extends Animal {
@Override
public void makesound() {
System.out.println("mooooooooooooo");
}
}
***************************************
package abstractclassdemo;
public class Tiger extends Animal {
public void makesound(){
System.out.println("roarrrrrrrrr");
}
}
***********************
package abstractclassdemo;
public class AbstractClassDemo {
public static void main(String[] args) {
AbstractClassDemo obj=new AbstractClassDemo();
Animal tigerobj=new Tiger();
Animal sheepobj=new sheep();
obj.SpecficSound(tigerobj);
}
public static void SpecficSound(Animal animal){
animal.makesound();
}
}
0 comments:
Post a Comment