Property and method access

We will learn a great deal about inheritance in the next section, but here is a pretty picture that shows how private, protected, and public keyword usage on properties and methods helps you control their access across classes.

Property and method access

In the previous figure, Class A defines three properties a, b, and c, which are private, public, and protected, respectively. Class B, which is a subclass of A, may freely access and modify the public and protected variables of Class A as if it were its own, though it may not access Class A's private properties. Class C, which is a not related to Class A or B, may only access A's or B's public properties. Note that the inherited public properties, such as A may be accessed via an instance of B even though it is defined in A. This is because of the subclass definition that B inherits all public and protected of its parent class. These access rules apply exactly the same way for methods as it does for properties.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.69.185