What will be the result of the program?

package tutorial.base;

public class TypesTutorial {

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

class A {
    A(){
        System.out.print("A");
        a();
    }
    
    void a() {
        System.out.print("a");
    }
}

class B {
    B() {
        System.out.print("B");
        a();
    }
    
    void a() {
        System.out.print("b");
    }
}
Explanation
Compilation error in the method main, since classes are not related by inheritance.

Follow CodeGalaxy

Mobile Beta

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