How to skip one level in inheritance causing super from grandparents in java?

I have three simple classes:

class A { public A(int a){ } } class B extends A { public B(int b){ super(b); } } class C extends B { public C(int c){ super(c); } } 

Thus, the execution order during the class increment is C-> B-> A-> B-> C, and all objects are created correctly. Then the question is:

I can somehow write a constructor for class C as follows:

  public C(int c){ super.super(c); } 

The idea is to call the constructor from class A, and not from the immediate parent of B. Is this possible?

+5
source share
1 answer

No, you cannot do this.

All classes in the hierarchy must be built. You cannot get around construct B

What you can do is write the protected constructor in B , which is essentially a non-operator, and call it from the constructor in C

+10
source

Source: https://habr.com/ru/post/1259272/


All Articles