public class Test {
public String xyz(){
String name="stack";
return name;
}
public static void main(String[] args) {
Test t=new Test();
t.xyz(); //this should stack isn't it??
}
}
Run Code Online (Sandbox Code Playgroud)
该方法确实返回一个值(类型String),但您的代码会丢弃它.
t.xyz(); // This calls the method and discards the return value
Run Code Online (Sandbox Code Playgroud)
如果要查看返回值,请将其分配给变量并将其打印出来:
String str = t.xyz();
System.out.println(str);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
51 次 |
| 最近记录: |