Q:

II tried to set a value using a different method, but I got compiler errors

This is my code:
public class Point3D {    
    public static void main(String args[]) {    
        int x=setX(x);
        System.out.println(x);
    }
    int x=1;
    public int setX(int x) { 
        this.x=x;
    }   
}

The compiler(cmd) showed the following errors:
Point3D.java:5: error: non-static method setX(int) cannot be referenced from 
static context int x=setX(x);
  ^
1 error

Can anyone please help me fix this?

A:

1)
 public int setX(int x) { 
        this.x=x;
    } 

That method needs to return an int value. You are not returning anything.
   public int setX(int x) { 
            this.x=x;
            return this.x;
        } 

My recommendation:
It's quite confusing to return an value from setter, provide getter and get the x value from there.
2)
Since the method setX is not a static method you cannot access it in static context. So either you need to make that method as static or you must create a instance of the class to access that method.
public class Point3D {  
    int x=1;  
    public static void main(String args[]) {   
      Point3D  p = new Point3D(); 
        p.setX(1);
        int x=p.getX();
        System.out.println(x);
    }

    public void setX(int x) { 
        this.x=x;
    }

     public int getX() { 
        return this.x;
    }   
}

