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
What is the use of beaninfo?
What is the reason behind using constructors and destructors?
Can java list be null?
How many characters is 16 bytes?
How many return statement are allowed in a function?
what is the purpose of using rmisecuritymanager in rmi?
Is java free for commercial?
Can we serialize singleton class?
Why is logger singleton?
What is the primitive type byte?
What is difference between arraylist and list in java?
Is it possible to write a regular expression to check if string is a number?
Where to store local variables?
What is static method with example?
Give an example of use of pointers in java class.