package demo;
public class Demo5 {
//构造器
Demo5(String name,int age, String color,String action){
this.name = name;
this.age = age;
this.color = color;
this.action = action;
}
//成员变量
String name;
int age;
String color;
String action;
//方法
String fa() {
return this.color + "的" + this.name + "正在" + this.action;
}
void go() {
System.out.println(this.name + "正在奔跑");
}
public static void main(String[] args) {
Demo5 dog = new Demo5("dog",5,"黑色","奔跑");
System.out.println(dog.age);
System.out.println(dog.fa());
dog.go();
}
}
JAVA面向对象练习
最新推荐文章于 2019-12-30 21:43:31 发布