public class Animal {
public void eat(){
System.out.println("吃饭");
}
}
class Dog extends Animal{
@Override
public void eat() {
System.out.println("狗吃骨头");
}
public void lookDoor(){
System.out.println("狗看门");
}
}
class Cat extends Animal{
@Override
public void eat() {
System.out.println("猫吃鱼");
}
public void CatchMouse(){
System.out.println("猫抓老鼠");
}
}
public class MyTest {
public static void main(String[] args) {
Animal an=new Cat();
an.eat();
((Cat) an).CatchMouse();
Animal bn=new Dog();
bn.eat();
((Dog) bn).lookDoor();
}
}
public abstract class Animal {
public String name;
public int age;
public abstract void eat();
}
class Dog extends Animal{
@Override
public void eat() {
System.out.println("狗吃骨头");
}
public void lookDoor(){
System.out.println("狗看门");
}
}
class Cat extends Animal{
@Override
public void eat() {
System.out.println("猫吃鱼");
}
public void CatchMouse(){
System.out.println("猫抓老鼠");
}
}
public class MyTest {
public static void main(String[] args) {
Animal an=new Dog();
an.name="小狗";
an.age=3;
System.out.println(an.name+"===="+an.age);
an.eat();
((Dog) an).lookDoor();
Animal bn=new Cat();
bn.name="小猫";
bn.age=1;
System.out.println(bn.name+"==="+bn.age);
bn.eat();
((Cat) bn).CatchMouse();
}
}
public abstract class Animal {
public String name;
public int age;
public abstract void eat();
public abstract void sleep();
}
class Dog extends Animal{
@Override
public void eat() {
System.out.println("吃骨头");
}
@Override
public void sleep() {
System.out.println("睡大觉");
}
}
public interface JumpInterface {
void jump();
}
public class BigDog extends Dog implements JumpInterface{
@Override
public void jump() {
System.out.println("学会了跳高");
}
}
public class MyTest {
public static void main(String[] args) {
Animal a=new Dog();
a.name="小白";
a.age=1;
System.out.println(a.name+"==="+a.age);
a.eat();
a.sleep();
Animal b=new BigDog();
b.name="小黑";
b.age=2;
System.out.println(b.name+"==="+b.age);
((BigDog) b).jump();
}
}