Quote:
Clear me friends.
Object class is the base class for all classes. Thus the methods with protected access in the object class can be invoked by any object(Of any class).
I know the statement is wrong!.
|
It's not wrong but it needs a bit more detail: a protected method is visible in any
of the (descending) classes where the method is defined. So not just any other
object can invoke that method on any other object, i.e. it has to be at least a
descendant of the other object's class. A short example:
-
class B { protected void m() { ... } }
-
class D extends B { ... }
-
class E extends B { ... }
-
class Derived extends D { ... }
-
...
Now any D can call m() on any B and D. Any E can call m() on any E and B
and any Derived can call m() on any other Derived, D and B but not on an E object.
But none of the D objects can call m() on an E object, nor can any E object
call m() on any D object.
kind regards,
Jos