public class Base
{
private int num;
Base(int n)
{
num=n;
}
public void display()
{
System.out.println(num);
}
}
class Sub extends Base
{
Sub()
{
super(20);
}
}
class Main
{
public static void main(String[] args)
{
Sub s=new Sub();
Base b=new Base(10);
s.display();
b.display();
}
}
Output:
20
10
In above program code, 2 values are stored in the memory 20 and 10, that means while creating object for child class memory allocation for data member num has done. Whether that means private data member num gets inherited..? These are my views. But in java clearly stated that private members are not inherited..
Someone please provide me with the true logic