Access modifiers inheritance: on final methods in abstract classes

102 Views Asked by At

Is the access visibility of implicit inherited methods (parent's abstract final methods inherited on children) always the same when accessed through child?

What are the implicit forwarded rules?

class package0.Parent {ACCESS_MODIFIER final void f();}   
class package1.B extends A { /* Implicit f?*/} 
class package2.C extends B {/* Implicit f? */}

Then: Will always ACCESS_MODIFIER be forwarded? If so, why case 1?. And what about case 3?

  • Case 1: If parent f() is private visibility is not forwarded, as B cannot see it.
  • Case 2: If parent f() is public, I guess anyone who uses B or C will have availability on f.
  • Case 3: If parent f() is protected, I guess B will "expose" the method as protected, which means C can see it.
1

There are 1 best solutions below

0
On

Your wording is semi-unclear. The way I'm interpreting your question is:

class A{protected void f();}
class B extends A{/* Can see f. */}
class C extends B{/* Can see f? */}

If so, the answer is yes: C would be able to access f.