I made the access restrictor of one of the elements private to design the class elements private. How can I get the value of stubIWant from the code below?
class IWasDesignedPoorly {
private int stuffIWant;
}
IWasDesignedPoorly obj = ...;
Access to the element designated as private is only possible within the class. Therefore, it is recommended that you define a method in the class that allows access to that element.
public void setStuffIWant(int value){
stuffIWant = value;
}
public int getStuffIWant(){
return stuffIWant;
}
You can do it like this.
© 2024 OneMinuteCode. All rights reserved.