‹ Back to the paper
Question 28
1 mark
Computer ScienceISC Computer Science - Competency Focused Practice Questions (CISCE, August 2024)Short answerInheritance, Interfaces and Polymorphism
Answer the following question.
What will happen if void show( ) in subclass Car is given access specifier as private?
Answer
Answer
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".