public class SuperClass{ public SuperClass(){ System.out.println("A"); } public SuperClass(String val){ System.out.println(String val); }} public class SubClass extends SuperClass{ public SubClass(){ //ここにコードを追加 } public SubClass(String val){ System.out.println(String val); } } public class Main(){ public static void main(String[] args){ new SubClass(); }} A: SubClass("B"); B: this("B"); C: super("B"); D: SuperClass("B") 正解:B ここで疑問なのですが、this("B")は自クラスだけのコンストラクトしか呼び出せない認識です。 親クラスのコンストラクタはどこで呼んでいるのでしょうか。 0013デフォルトの名無しさん (ワッチョイ ce2a-MWj7 [223.132.120.2])2018/06/12(火) 05:52:26.38ID:ixitVWbc0 ググってみた。これとか。 ttps://qiita.com/katolisa/items/438a8d720ea5a60b55c4 0014デフォルトの名無しさん (ワッチョイ 4eb6-qo/L [111.90.12.245])2018/06/12(火) 06:11:33.73ID:AQnxwR2X0>>12 https://docs.oracle.com/javase/specs/jls/se10/html/jls-8.html#jls-8.8.7
If a constructor body does not begin with an explicit constructor invocation and the constructor being declared is not part of the primordial class Object, then the constructor body implicitly begins with a superclass constructor invocation "super();", an invocation of the constructor of its direct superclass that takes no arguments.
コンストラクタの呼び出しが明示されてなければ super()が暗黙的に呼ばれますよと
public SubClass(String val) { // ここでsuper()が呼ばれる System.out.println(val); }