Computer Applications
Suppose, 'Happening' and 'Accident' are two classes. What will happen when Happening class derives from Accident class by using private visibility?
Encapsulation & Inheritance in Java
19 Likes
Answer
Java only supports public inheritance. If 'Happening' class derives from 'Accident' class in Java, then 'Happening' class will inherit all the public and protected data members and member methods of 'Accident' class. Public members of 'Accident' class will behave as public members of 'Happening' class and protected members of 'Accident' class will behave as protected members of 'Happening' class. Private members of 'Accident' class will not be accessible in 'Happening' class.
Answered By
10 Likes
Related Questions
What is meant by scope of variables? Show its application with the help of an example.
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.
Give reasons:
(a) In what circumstances is a class derived publicly?
(b) In what circumstances is a class derived privately?
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.