class Person
{
private int age;
public void setAge(int a)
{
if(a>0&&a<130)
{
age=a;
speak();
}
else
System.out.println(false);
}
public int getAge(int a)
{
return age;
}
void speak()
{
System.out.println("age="+age);
}
}
class Persondemo
{
public static void main(String[] args)
{
Person a=new Person();
a.setAge(-20);
//a.speak();
}
}
请问小伙伴们为什么上面的方法写法是public void setAge()和public int getAge()而不写成public static void setAge()和public static int getAge();请大家帮忙解答一下,谢谢啦!
|
|