如果我只能键入yourDog._name,为什么我需要getter.dod.getName()?This Java Compiler gives no errors这是因为我正在使用在线编译器吗?
public class Dog {
private String _name;
private int _age;
public Dog (String name, int age){
_name = name;
_age = age;
}
public void setAge (int age){
_age = age;
}
public int getAge (){
return _age;
}
public String getName(){
return _name;
}
public static void main(String args[]) {
Dog yourDog = new Dog("Tommy", 50);
System.out.println(yourDog.getName());
System.out.println(yourDog.getAge());
System.out.println(yourDog._name);
}