Question
Question 6 What is the output of following program: public class Test { public static void main(String[] args) { B b = new B(2); b.methodAB();
Question 6
What is the output of following program:
public class Test {
public static void main(String[] args) {
B b = new B(2);
b.methodAB();
}
}
class A {
public A() {
System.out.println("A's constructor is executed");
}
public void methodA() {
System.out.println("methodA is executed");
}
public void methodAB() {
System.out.println("A's methodAB is executed");
}
}
class B extends A {
private int num = 0;
public B() {
super();
System.out.println("B's constructor is executed");
}
public B (int n)
{
num = n;
System.out.println("B's constructor is executed");
}
public void methodB() {
System.out.println(num is + num);
System.out.println("methodB is executed");
}
public void methodAB() {
System.out.println("B's methodAB is executed");
}
}
| A. | B's constructor is executed B's methodAB is executed |
| B. | Compiling time error because both classes A & B have methodAB. |
| C. | B's constructor is executed A's methodAB is executed |
| D. | A's constructor is executed B's constructor is executed B's methodAB is executed |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started