不好意思,是这样的:
public class PrivateTest1 

public static void main(String[] args) 

PriTest atestnex = new PriTest("Test"); 
System.out.print(atestnex.fuc()); 
} class PriTest 

public PriTest(String test) 

t=test; 
} public String fuc() 

t = "This is " + t; 
return t; 
} private String t; 


解决方案 »

  1.   

    不好意思,是这样的:
    public class PrivateTest1 

    public static void main(String[] args) 

    PriTest atestnex = new PriTest("Test"); 
    System.out.print(atestnex.fuc()); 
    } class PriTest 

    public PriTest(String test) 

    t=test; 
    } public String fuc() 

    t = "This is " + t; 
    return t; 
    } private String t; 

    }
    为什么编译时提示出错: 
    在静态上下文中不能引用非静态变量 this 
    PriTest atestnex = new PriTest("Test"); 
      

  2.   

    因为PriTest是PrivateTest1的内隐类,而非静态的inner class对象被产生时,一定得关联
    至其enclosing class的某个对象。 因此如果不修改你这个程序的结构,在main()函数中作如下修改
    PrivateTest1  a=new PrivateTest1();
    PriTest atestnex = a.new PriTest("Test"); 
    System.out.print(atestnex.fuc());
      

  3.   

    同样Employee是EmployeeSortTest1的内部类,为什么Employee构造对象时不会出错呢?
    public class EmployeeSortTest1
    {
    public static void main(String[] args)
    {
    Employee staff = new Employee("Angel",6666);
    System.out.println("Before "+staff.getName()+",salary is "+staff.getSalary());
    }
    }class Employee
    {
    public Employee(String n,double s)
    {
    name = n;
    salary = s;
    } public String getName()
    {
    return name;
    } public double getSalary()
    {
    return salary;
    } private String name;
    private double salary;
    }
      

  4.   

    请注意大挎号的位置,Employee并不是EmployeeSortTest1的inner class