Can you call a private data from an inner class?
Answers were Sorted based on User's Feedback
Answer / ejp
The question is completely meaningless. You can't 'call'
private data at all. You call _methods_.
You can _access_ private data members from anywhere in the
enclosing scope, which includes inner classes.
| Is This Answer Correct ? | 7 Yes | 2 No |
Answer / sudhakar
when ever we declare a variable as private in Outer
class,that variable we can access from Inner class.
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / jettimadhuchowdary
public class MainTest {
private int localPr =1;
public int localPb = 20;
protected int localPro = 3;
int localDf = 5;
/**
* @param args
*/
public static void main(String[] s) {
// TODO Auto-generated method stub
MainTest mainTest = new MainTest();
InnerClass class1 = mainTest.new InnerClass();
class1.call();
}
class InnerClass
{
void call() {
System.out.println(" display data localDf ="+ localDf);
System.out.println(" display data localPro ="+ localPro);
System.out.println(" display data localPb ="+ localPb);
System.out.println(" display data localPr ="+ localPr);
}
}
}
and the output is
display data localDf =5
display data localPro =3
display data localPb =20
display data localPr =1
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / venki mic
Yes Its possible.private date can be accessible with in the
class .
| Is This Answer Correct ? | 0 Yes | 4 No |
Answer / devarathnam c,kotagudibanda(po
Yes ,we can call even private data in an inner classes.
| Is This Answer Correct ? | 0 Yes | 4 No |
when there is a need of jvm then how we can say that java is a platform independent language?
What are the different ways to handle exceptions?
Why does java have two ways to create child threads? Which way is better?
Explain the differences between static and dynamic variables?
What’s meant by anonymous class?
What is the difference between size and length in java?
What is a class variable?
java is puerly object oriented or not ?
what is main difference between architecture,framework and design pattren
How many statements can be created with one connection in jdbc?
Hai all I want to print given array in reverse order Ex: int a[]={1,2,3,4,5};display this array in reverse order.
What are sets in java?