/**
* AWT Sample application
* @author foreverlove111
* @version 1.00 17/10/17
*/
public class Zoo {
public static void main(String[] args) {
Animal a1=new Animal(); //类的实例化
a1.name="老虎";
a1.age=3;
System.out.println("name:"+a1.name+" age:"+a1.age);
a1.eat();
a1.sleep();
}
}
class Animal{
String name;
int age;
public void eat(){
System.out.println("动物进食");
}
public void sleep(){
System.out.println("动物休眠");
}
public String getName(){
return name;
}
public void setName(String n){
name=n;
}
}
创建java类并实例化对象
最新推荐文章于 2024-05-17 02:38:57 发布