A
Arvind
hi,
In Java if a superclass has a particular access specifier for a
method it is allowable by the subclass to broaden the access, but NOT
restrict it.
eg: class A
{
protected void print(){ }
}
class B extends A
{
private void print(){ } /* NOT ALLOWED! (It will be alowed if
it was protected or public) */
}
This is exactly the opposite of what is applicable in C++. Coming
from C++ , i find this strange, as this broadening rule, would expose
methods that a 'library' writer would not have wanted to expose. That
means clients could potentially write malicious code using this
concept, whereas in C++ one can prevent the clients from having access
to it and control to such methods can be controlled by a subclass.
Could someone please explain to me the reason behind such a design.
There must be something that iam missing. Please point it out.
Thanks
Arvind.
In Java if a superclass has a particular access specifier for a
method it is allowable by the subclass to broaden the access, but NOT
restrict it.
eg: class A
{
protected void print(){ }
}
class B extends A
{
private void print(){ } /* NOT ALLOWED! (It will be alowed if
it was protected or public) */
}
This is exactly the opposite of what is applicable in C++. Coming
from C++ , i find this strange, as this broadening rule, would expose
methods that a 'library' writer would not have wanted to expose. That
means clients could potentially write malicious code using this
concept, whereas in C++ one can prevent the clients from having access
to it and control to such methods can be controlled by a subclass.
Could someone please explain to me the reason behind such a design.
There must be something that iam missing. Please point it out.
Thanks
Arvind.