I use the protected modifier in the following code but it is not working as I would expect.
This is my Prob3.java file and I expected to have error when compiling ob1.x=4;
Can anyone explain why I'm not getting one?
class Coordinates2D{
protected int x,y;
public Coordinates2D(int x,int y){
this.x=x;
this.y=y;
}
public int getX(){
return this.x;
}
public int getY(){
return this.y;
}
public void setX(int val){
this.x=val;
}
}
public class Prob3{
public static void main(String[] args){
Coordinates2D ob1 = new Coordinates2D(3,4);
ob1.x=4;
System.out.println("Atributele ob 2D: "+ ob1.getX()+" , "+ob1.getY());
}
}