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 does pointer mean?
What is java oops?
What is variable and example?
What is google full form?
What is used of static keyword in java?
Does java support multiple inheritance or not?
List the features of java programming language.
How many threads can java run?
What are loops in java? What are three types of loops?
What is thread count in java?
What is stream api in java8?
Can you explain inner class.
What technique can be employed to compare two strings?
Can we sort hashset in java?
Explain method local inner classes ?