inheritance:
it is a mechanism in which one class acquire the
properties of another class allow us to create new class derived class from
existing class parent class derived class inherits the function from base class
and have additional functions to.
we use access specifiers to provide data security
access specifier:
i.
public : using this public keyword we allow anyone to access data anywhere he wants
ii.
protected: only child classes access data or class it self
iii.
private :no one can access data only class access the data
|
Public |
Protected |
Private |
Within class |
Yes |
Yes |
Yes |
Child class |
Yes |
Yes |
No |
Main |
Yes |
No |
No |
code:
No comments:
Post a Comment