Computer Applications
Give reasons:
(a) In what circumstances is a class derived publicly?
(b) In what circumstances is a class derived privately?
Answer
(a) In what circumstances is a class derived publicly?
In Java, a base class can be derived by a subclass by using only public mode of inheritance. When a class is derived publicly, the public and protected members of the base class are accessible to the derived class. Private members of the base class are not inherited by derived class.
(b) In what circumstances is a class derived privately?
Java doesn't support private and protected modes of Inheritance. Classes are always derived publicly in Java.
Related Questions
In what way does the access specifier of the base class have access control over the derived class? Show with the help of an example.
Suppose, 'Happening' and 'Accident' are two classes. What will happen when Happening class derives from Accident class by using private visibility?
Describe the methods of accessing the data members and member functions of a class in the following cases:
(a) in the member function of the same class.
(b) in the member function of another class.
(c) in the member function of base class.
Can a private member be accessed by
(a) a member of the same class?
(b) a member of other class?
(c) a function which is not a member function?