PRASHNIKAप्रश्निका
‹ Back to the paper

What will happen if void show( ) in subclass Car is given access specifier as private?

Computer Science20251 markShort answer

Answer

Answer

AI
Java does not allow an overriding method to reduce the visibility of the method it overrides. Since Vehicle's show() is public, making Car's show() private is not a valid override and causes a compile time error: "show() in Car cannot override show() in Vehicle; attempting to assign weaker access privileges; was public".
Inheritance, Interfaces and Polymorphism

From ISC Computer Science - Competency Focused Practice Questions (CISCE, August 2024), question 28.