倾讷
2020-07-20 18:05
帮忙看一下,为啥输出没有age那些赋值的参数。
public class IniTest1 {
public static void main(String[] args) {
Test1 test1=new Test1();
test1.age=120;
test1.height=199f;
test1.name ="Allen";
test1.eat();
test1.talk();
}
}public class Test1 {
String name;
int age;
float height;
void talk(){
System.out.println("You can talk to others");
}
void eat(){
System.out.println("You can eat what you want to ");
}
}只输出了以下内容
You can eat what you want to
You can talk to others
Process finished with exit code 0
sdfasd
我找到原因了。
你的值确实赋给各个参数了,参数值已经是你赋给他的值,但是你并没有print出这些属性值,想要输出的话,可以将这些参数写入printf语句中
Java入门第二季
531293 学习 · 6327 问题
相似问题