What will be the result of the launch of this code?

package tutorial.base;

public class TypesTutorial {
    public static void main(String... args) {
        A alpha = new B(0);
    }
}

class A {
    A(int x){            // - 1 -
        a(x);            // - 2 -
    }
    
    void a(int x) {
        System.out.println("A-a: " + x);
    }
}

class B extends A {
    B(int x) {           // - 3 -
        a(x);            // - 4 -
    }
    
    void a(int x) {
        System.out.println("B-a: " + x);
    }
}
Explanation
In class A there are no default constructor, so the constructor of the class B (child) should firstly explicitly call one of the advertised constructors of the parent class.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes