I have a class
class A {
private int x;
public void setX(...){...}
public int getX(){return x;}
}
class B {
int y;
public void setY() {
//Accessing x of A, assume I already have object of A
if(a.getX() < 0) {
y = a.getX();
}
}
}
class C {
int y;
public void setY() {
//Accessing x of A, assume I already have object of A
int tmpX = a.getX();
if(tmpX < 0) {
y = tmpX;
}
}
}
Which one is better way of coding? The way I have accessed x of A
in class B or in class C?