第一个为名为Animal的Java源文件
package Hello.lrx.nba;
public class Animal {
private int id;
private String name;
public Animal(int id, String name) {
this.id = id;
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "Animal{" +
"id=" + id +
", name='" + name + '\'' +
'}';
}
}
第二个名为Main的主函数Java文件
package Hello.lrx.nba;
public class Main {
public static void main(String[] args) {
Animal animal = new Animal(1001,"大黄");
System.out.println(animal.getId());
System.out.println(animal.toString());
}
}
调用结果为