I am trying to build a constructor for a class that represents an Object. Thing is I am not sure which way would be better, using getters/setters in my constructors/methods or just use the "=" operator (keep in mind this is exactly what my setter does).
public class Object{
int x;
public Object()
{
x = 1;
}
public Int objectsInt(Object other)
{
if(other!=null)
{
this.x = other.x;
return other.x;
}
else
{
return 0;
}
}
}
// or
public class Object{
int x;
public Object()
{
Object obj = new Object();
obj.setObjInt(1);
}
public int objectsInt(Object other)
{
if(other!=null)
{
Object obj = new Object();
obj.setObjInt(other.getObjInt)
return obj.getObjInt;
}
else
{
return 0;
}
}
public int getObjInt()
{
return x;
}
public void setObjInt(int x)
{
this.x = x ;
}
}
or maybe there is a different way I didn't think of. p.s. this is just a demonstration not my real code, the Object class is a lot more complex so I made it simple as possible for you to understand my intention.