0

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.
Whimusical
  • 6,401
  • 11
  • 62
  • 105
  • 1
    It's hard to understand what you mean here - particularly the "abstract's final" part. A short but complete piece of *code* with suitable questions for what's unclear to you would make it a lot easier to answer the question. – Jon Skeet Dec 10 '14 at 17:52
  • Improved wording, sorry – Whimusical Dec 10 '14 at 18:12
  • It's still not really clear what "forwarded" means. JLS 6.6 is probably the best resource here: http://docs.oracle.com/javase/specs/jls/se8/html/jls-6.html#jls-6.6 – Jon Skeet Dec 10 '14 at 18:17
  • forwarded means the following. I use an access modifier for the abstract class final method. And it usually forwards it so when a child exposes implicitly that method is indeed using same visibility. That means the visibility scope is forwarded across inheritance, but then private is an exception, as it has meaning per se and is not forwarded, it applies to the abstract class itself – Whimusical Dec 10 '14 at 18:20
  • Is the package stuff relevant to your question? And since you have edited it, shouldn't you remove the `abstract final` from the title. It's still confusing. – 5gon12eder Dec 10 '14 at 18:31
  • I think it's a language mistake, I mean final methods on abstract classes – Whimusical Dec 10 '14 at 18:32
  • In what way is that even relevant? Method visibility is neither affected by the parent class being `abstract` nor the method being `final`. – 5gon12eder Dec 10 '14 at 18:35
  • Well yes in some degree. As method is final it cannot be extended, and as a result of that, his availability when called over a child class needs to be inferred from the forwarding laws of the modifier (which is the point of my question) – Whimusical Dec 10 '14 at 18:36
  • There is no difference between an inherited `final` method (which must not be overridden) and an inherited non-`final` method (which just *happens* to not be overridden). – 5gon12eder Dec 10 '14 at 18:38
  • Now I got you. You mean whether I override or not wither final and non-final methods are implicitly available. You are right in that case, I never thought of that. Anyway, at least in the non final I can make a method wrapper and change its visibility just to call parent's one – Whimusical Dec 10 '14 at 18:41

1 Answers1

0

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.

Bertie Wheen
  • 1,215
  • 1
  • 13
  • 20