Reputation: 9516
I have a class A private method 1
class B extends A private method 1 (Same name)
When I instantiate B and method 1 gets called from class A. I made them both protected and that solved it. Is there a way to keep both private and still get class B's method 1 to be called?
Upvotes: 0
Views: 65
Reputation: 236170
Take a look at this explanation of the visibility modifiers from the java tutorials, it'll be clear after that
Upvotes: 2
Reputation: 10187
private methods are only accessible from that specific class so you can't override them. You can have method with same name and arguments in a subclass and there will be no errors, but it will not override it.
Upvotes: 0
Reputation: 1967
No. Private is designed for that class and that class alone.
Protected is designed for any subclesses to know about, use and override if required.
Upvotes: 0