定义一个animal类 //java上转型对象 public class Animal { public String name=“动物”; public String getName(){ return name; } public void action(){ System.out.println(“动物都在我的分类之中”); } public void feature(){ System.out.println(“我们都很帅气”); } } 定义一个dog类 public class dog extends Animal{ public String name=“狗”; public String getName(){ return name; } public void action(){ super.action(); System.out.println(“我是一只狗”); } public void drink(){ System.out.println(“我会喝水”); } } 定义一个测试类 public class test01 { public static void main(String[] args){ Animal dog=new dog(); dog.action(); dog.feature(); ((dog) dog).drink(); String name1=((dog) dog).name; System.out.println(name1); System.out.println(dog.name); System.out.println(dog.getName()); //((dog)dog.drink()); } }