3
Answers

How to call parent constructor? Not base one.

Zagiel

Zagiel

15y
9.8k
1
public class A { int a; public A(int a) {this.a = a;} }
public class AB : A { int a; int b; public AB(int a, int b) : base(a) { this.b = b; } }
public class ABC : AB { int a; int b; int c; public ABC(int a, int b, int c) : AB(a, b) { this.c = c; } }
The call of AB(a, b) in ABC() is forbidden. All I can use there seems to be this() or base(). Is there a way to call the constructor of the closest parent, not the one of the oldest ancestor?
Answers (3)