Question: What is the output of the following JAVA code? class A { static void m(A x) { System.out.println(AA); } } class B extends A {

What is the output of the following JAVA code?

class A {

static void m(A x) { System.out.println("AA"); }

}

class B extends A {

void m(A x) {

if (x instanceof B) {

System.out.println("BB");

} else {

System.out.println("AB");

}

}

public class Test {

public static void main(String[] args) {

A a1 = new A();

A a2 = new B();

B b1 = new B();

a1.m(a1);

a2.m(b1);

b1.m(b1);

b1.m(a2);

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!