Originally posted by Tausif Khanooni:
Just remove "c." while accessing the protected method at line 17. this way you can avoid compilation error at this line. because C class imports A and having a "HAS-A" relation.
rest of the methods can not be accessed.
Since Class C extends class A then it is possible for Class C to access protected methods of Class A even though Class C and Class A are declared in different packages. The relationship between Class C and Class A is an "is-a" relationship because Class C "is-a" subclass of class A. Therefore, a compilation error does NOT occur at line 17.
If the reference, c, is removed from the statement at line 17 then a compilation error will occur due to an attempt to invoke an instance method from a static context.
An example of a "has-a" relationship would be a delagation relationship where one class "has-a" member that is an instance of a class.