Can you override a private method in Java 2024?
I'll answer
Earn 20 gold coins for an accepted answer.20
Earn 20 gold coins for an accepted answer.
40more
40more
Works at the International Air Transport Association, Lives in Montreal, Canada.
No, a private method cannot be overridden since it is not visible from any other class. You have declared a new method for your subclass that has no relation to the superclass method. One way to look at it is to ask yourself whether it would be legal to write super.func() in the Derived class.
2023-05-12 12:30:15
评论(499)
Helpful(122)
Helpful
Helpful(2)

Charlotte Ross
QuesHub.com delivers expert answers and knowledge to you.
No, a private method cannot be overridden since it is not visible from any other class. You have declared a new method for your subclass that has no relation to the superclass method. One way to look at it is to ask yourself whether it would be legal to write super.func() in the Derived class.