‹ Back to the paper
What will happen if void show( ) in subclass Car is given access specifier as private?
Answer
Answer
AIJava 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".
From ISC Computer Science - Competency Focused Practice Questions (CISCE, August 2024), question 28.