How to access a variable if it is declared as private?
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / ravikiran(aptech mumbai)
the variable declared as private can be accessed with in the
same class only
| Is This Answer Correct ? | 2 Yes | 2 No |
Answer / neo
You can access the private variable in to the other package
or other classes by inheritance . to inherite the super
classes all the resources comes in to sub classes private
also in this context.
| Is This Answer Correct ? | 1 Yes | 2 No |
What is += mean in java?
What is super keyword explain with example?
What is difference between identifier and variable?
Can main() method in java can return any data?
Explain about map interface in java?
Does list allow duplicates in java?
What is bubble sort in java?
What is a Java Virtual Machine?
What is operator?
Why java is not a pure object oriented language?
What are the disadvantages of object oriented programming?
Is there is any difference between a scrollbar and a scrollpane?