public class 类的创建和使用 {
static class Person{
String a ;
int b;
void eat(){
System.out.println("我想吃东西");
}
void play(){
System.out.println("我想玩");
}
}
public static void main(String[] args) {
Person p = new Person(); //创建Person对象
p.a="优卡云";
p.b=2;
System.out.println(p.a);
System.out.println(p.b);
p.eat(); //利用对象调用Person类中的eat方法
p.play();
}
}里插入代码片
类的创建和使用_04
最新推荐文章于 2024-03-06 13:30:51 发布