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 three dots mean in java?
Are strings immutable in java?
How do you escape in java?
Is 64bit faster than 32 bit?
Can we overload the constructors?
What is getclass () getname () in java?
What are the advantages of arraylist over arrays?
How to run a JAR file through command prompt?
What is the similarity between dynamic binding and linking?
Can you inherit from an abstract class java?
What do you mean by chromounits in java8?
What is the advantage of preparedstatement over statement?
Highest level event class of the event-delegation model?
Can we use string in switch case in java?
How many types of memory areas are allocated by jvm?