While inheriting a class in C++, user can specify the access specifier like,
class Base
{
public int mem1;
protected in mem2;
};
class Derived1 : **private** Base
{
// mem1 will be private here.
// mem2 will be private here.
};
class Derived2 : **protected** Base
{
// mem1 will be protected here.
// mem2 will be protected here.
};
class Derived2 : **public** Base
{
// mem1 will be public here.
// mem2 will be protected here.
};
But the same is not possible in Java, i.e. extends in java is always like "public" inheritance in C++.
Could someone explain the reason for this?