狗类Dog
属性:姓名name,年龄age
行为:吃饭eat,看家lookHome
class Dog {
public static void main(String[] args) {
Dogl a =new Dogl();
a.setName("狗");
a.setAge(4);
System.out.println(a.getName()+" "+a.getAge());
a.eat();
a.lookHome();
}
}
class Dogl{
private String name;
private int age;
public void setName(String name){
this.name =name;
}
public String getName(){
return name;
}
public void setAge(int age)
{
this.age =age;
}
public int getAge()
{
return age;
}
public void eat(){
System.out.println("吃饭");
}
public void lookHome(){
System.out.println("看家");
}
}
|
|