public class main {
public static void main(String[] args) {
Human human1=new Human("Rick",24,90);
Human human2=new Human("Jim", 12,90);
System.out.println(human1.name);
human1.eat();
human2.drink();
}
}
public class Human {
String name;
int age;
double weight;
Human(String name,int age,double weight){
this.name=name;
this.age=age;
this.weight=weight;
}
void drink() {
System.out.println(this.name+" is drinking.");
}
void eat() {
System.out.println(this.name+" is eating.");
}
}
运行结果:
Rick
Rick is eating.
Jim is drinking.