This discussion is archived
11 Replies Latest reply: Apr 12, 2012 12:35 AM by 930029 RSS

inner classes private member accessed in sub class?

930029 Newbie
Currently Being Moderated
Hello All,

Can some one tell me in following code how is it possible to call private function, private variable and private constructor of class A from class B?

This program runs well and gives output

abcd
test
3

class Doubt
{
class A{
private int privt_var=3;
private A(int x)
{
System.out.println("abcd");
}

private void test()
{
System.out.println("test");
}
}



class B extends A
{
B(int x)
{super(x);
super.test();
System.out.println(super.privt_var);
}
}


public static void main(String args[])
{
Doubt.B exp=(new Doubt()).new B(3);
}

}

Edited by: 927026 on Apr 11, 2012 11:24 AM

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points