当前位置: 技术问答>java相关
请帮忙解释一下这个问题
来源: 互联网 发布时间:2017-04-05
本文导语: public class Outer{ public class Outer{ public String name = "Outer"; public static void main(String argv[]){ Inner i = new Inner(); i.showName(); }//End of main private class Inner{ String name =new String("Inner"); void showName(){ System.out.println(name); }...
public class Outer{
public class Outer{
public String name = "Outer";
public static void main(String argv[]){
Inner i = new Inner();
i.showName();
}//End of main
private class Inner{
String name =new String("Inner");
void showName(){
System.out.println(name);
}
}//End of Inner class
}
实际编译过程中有提示在创建Inner类实例i的时候提示non-static variable this cannot be referenced from a static context,请问各位高手这是怎么回事呢
public class Outer{
public String name = "Outer";
public static void main(String argv[]){
Inner i = new Inner();
i.showName();
}//End of main
private class Inner{
String name =new String("Inner");
void showName(){
System.out.println(name);
}
}//End of Inner class
}
实际编译过程中有提示在创建Inner类实例i的时候提示non-static variable this cannot be referenced from a static context,请问各位高手这是怎么回事呢
|
public class Outer{
public String name = "Outer";
Inner i = new Inner();
public static void main(String argv[]){
//Inner i = new Inner();
Outer o = new Outer();
o.i.showName();
//i.showName();
}//End of main
class Inner{
String name =new String("Inner");
void showName(){
System.out.println(name);
}
}//End of Inner class
}
或是
public class Outer{
public String name = "Outer";
public static void main(String argv[]){
Inner i = new Inner();
i.showName();
}//End of main
static class Inner{
String name =new String("Inner");
void showName(){
System.out.println(name);
}
}//End of Inner class
}
------------------------结论吗,建议自己总结