What will be the following program's output?

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 extends A {
    B() {
        System.out.print("B");
        a();
    }
    
    void a() {
        System.out.print("b");
    }
}
Explanation
Class A constructor will be called first. Overridden method from child class B is called from it, according to the type of the object created. Next, the constructor of the class B is called, which, in turn, calls the same method again.

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Продолжайте изучать
тесты по Java
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты