编程语言
首页 > 编程语言> > 【Java学习】-Constructor

【Java学习】-Constructor

作者:互联网

public class Main {

public static void main(String[] args) {
Human human1 = new Human("Rick", 65, 70);
Human human2 = new Human("Morty", 66, 77);
human2.eat();
human1.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 eat() {
System.out.println(this.name + " is eating");
}
void drink() {
System.out.println(this.name + " is drinking");
}
}

标签:Java,name,weight,age,学习,Human,Constructor,public,String
来源: https://www.cnblogs.com/yidianling/p/15831322.html