This week's book giveaway is in the Programmer Certification forum. We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer (Exam 1Z0-830) Java SE 17 Developer (Exam 1Z0-829) Programmer’s Guide and have Khalid Mughal and Vasily Strelnikov on-line! See this thread for details.
Hi,
Suppose i am having a class x which contains a protected method. The class x resides in a package say A. Now another class in package B extends this class x in package A and tries to override the protected method in class x. Now what will be the access modifier of this method in the subclass? Is it private? will the compiler fail if we assign "weaker" privileges to the overriden methods? Please clarify.
Harshit Rastogi wrote:
For eg, in your case the protected method can be overriden with public and protected modfier. if you put private, compile time error will be there
Even can't extends class X since it is in different package