[英]A Basic Class Problem about String and the object returned
Since 'A's are an object, you need a constructor.由于'A'是一个object,你需要一个构造函数。 So you would likely have something like:所以你可能会有类似的东西:
public A(String name){
this.name = name;
}
After this, you need to overwrite toString(), since 'A's are objects and printing them normally will not work.在此之后,您需要覆盖 toString(),因为 'A' 是对象并且通常无法打印它们。 Thus, you would then need:因此,您将需要:
public String toString(){
return this.name;
}
Thus, when you call SoPL(), it will run this version instead of Object.toString()因此,当您调用 SoPL() 时,它将运行此版本而不是 Object.toString()
Consider method with name A, where you are creating an object of A and can pass the parameter as a string, then the method A can return a string which belongs to the variable考虑名称为 A 的方法,您在其中创建 A 的 object 并且可以将参数作为字符串传递,然后方法 A 可以返回属于该变量的字符串
called name = myvalue;称为名称= myvalue;
It Means它的意思是
public A(String name){
this.name = name;}
String name = myvalue;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.