【发布时间】:2020-08-26 00:25:33
【问题描述】:
//我现在想知道为什么我不能在下面的java代码中打印出返回值
public class client08 {
public static void main(String[] args) {
String w=test();
System.out.println(w);**// I'd like to print out the return value here but it now work**
}
public String test() {
String result="";
String[] words=new String[5];
words[0]="Amy";
words[2]="Tom";
words[4]="Jane";
for(int i=0; i<words.length;i++) {
if(words[i]!=null) {
result=words[i].toUpperCase();
}else {
result="null";
}
}
return result;
}
【问题讨论】:
-
您必须更具体地了解问题。它是关于从静态上下文调用非静态方法的吗?