class Outer{
private static final int b = 0;
// public static void m() {
class Inner {
int a = b; //不报错
public void fun(){
System.out.println(b);//输出b
}
}
// System.out.println(b);//不报错
// }
public void print(){
new Inner().fun() ; //此处错误
}
}
public class Demo6{
public void main(String args[]){
Outer out = new Outer() ;
out.print() ;
}
类名点只能调用静态的 不能调用非静态的
class Outer{
private static final int b = 0;
// public static void m() {
class Inner {
int a = b; //不报错
public static void fun(){ //把static 去掉就OK了
System.out.println(b);//输出b
}
}
// System.out.println(b);//不报错
// }
public static void print(){ //把static 去掉就OK了
new Inner().fun() ; //此处错误
}
}
public class Demo6{
public void main(String args[]){
Outer out = new Outer() ;
out.print() ;
}
主函数也写错了[]在String后面
public class Demo6{
public static void main(String arg[]){
Outer out = new Outer() ;
out.print() ;
}
}
public class Demo6{
public static void main(String[] args){
Outer out = new Outer() ;
out.print() ;
}
}
作者: 月光海 时间: 2014-4-17 15:42
给你改了下代码
public class Help {
public static void main(String[] args) {
Outer.print();
}
}
class Outer{
private static final int b = 0;
// public static void m() {
class Inner {
int a = b; //不报错
public void fun(){
System.out.println(b);//输出b
}
}
// System.out.println(b);//不报错
// }
public static void print(){
new Outer().new Inner().fun() ; //此处错误,要先new Outer