我在网上找到了一个教程,但我真的不明白结果怎么可能是这样的:
Passed Name is :tommy
这是代码:
public class Puppy {
public Puppy(String name) {
// This constructor has one parameter, name.
System.out.println("Passed Name is :" + name);
}
public static void main(String[] args) {
// Following statement would create an object myPuppy
Puppy myPuppy = new Puppy("tommy");
}
}
它到底在哪里说name = tommy
?我认为它至少可以使用类似 ("passed Name is :" + myPuppy)
.
谁能帮我理解这一点?