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