How to access a variable if it is declared as private?
Answer Posted / ranganathkini
If a variable inside a class is marked private then it
cannot be accessed directly.
Access to this variable can only be provided by a public
accessor and mutator methods. Example:
class MyClass {
private int dataValue;
public int getDataValue {
return dataValue;
}
public void setDataValue( int newValue ) {
dataValue = newValue;
}
}
Is This Answer Correct ? | 7 Yes | 2 No |
Post New Answer View All Answers
Can we override tostring method in java?
Can we execute a program without main() method?
What is a qms manual?
What do you understand by the term string pool?
Is integer immutable in java?
why java does not support unsigned keyword?
Explain inheritance in java?
How many types of memory areas are allocated by JVM in java?
Why java is used everywhere?
What is array and arraylist in java?
What methodology can be employed to locate substrings inside a string?
What is instance example?
Give reasons supporting that string is immutable.
What is bool mean?
What is difference between null and void?