System.out.println("x = " + x);
错了

解决方案 »

  1.   

    去掉这句!
    System.out.println("x = " + x);
      

  2.   

    不知道楼主想要什么结果?
    class TestClassValue
    {    
     int x=12;
    TestClassValue(){
    int y = 1;
    }
    public static void main(String[] args) 
    {
    TestClassValue i = new TestClassValue();
    System.out.println("x=" + i.x);
    }
    }————————————————————————————
    class TestClassValue
    {    
     int x=12;
    TestClassValue(){
    int y = 1;
    System.out.println("y = "+y);
             System.out.println("x = "+x );
    }
    public static void main(String[] args) 
    {
    TestClassValue i = new TestClassValue();
    }
    }
      

  3.   

    不好意思,楼上的第一个程序少了点东西
    class TestClassValue
    {    
     int x=12;
    TestClassValue(){
    int y = 1;
    System.out.println("y = "+y);
             System.out.println("x = "+x );
    }
    public static void main(String[] args) 
    {
    TestClassValue i = new TestClassValue();
    System.out.println("x=" + i.x);   //可以这样
    }
    }
      

  4.   

    System.out.println("x = " + x);
    这句话应该写在你类中定义的某个方法中,在方法之外,一般只允许定义变量的
      

  5.   

    不然JAVA怎么中完全面向对象?