定义一个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());
}
}
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.e1idc.net