question 4 What is the output of following program: public class Test { public static void main(String[] args) { A a = new A(); a.methodB(); } } 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"); } }



Answer :

Answer:

The answer to this question can be given as:

This program will give an error message that is cannot find symbol.

a.methodB(); //error  

Explanation:

In this question, the program will give an error message that is cannot find symbol. Because in this question there are three class Test, class A, and class B. In this question first, we explain class A and class B then the class Test. In class A we create constructor then we create two methods that is methodA() and methodAB(). In the constructor and methods, we print  the message.  In class B class inherits class A. In this class we declare an integer variable that is used as a parameter in the parameterized constructor. but first, we declare the default constructor then parameterized constructor. In the default constructor, we use the super keyword. Super keyword is  used to call the above class method or constructors. Then we declare the two methods that are methodB() and methodAB ()  in these methods we print messages.  Then we define the main class that is the class Test. In this class, we define the main method and create class A object and call the class B method. that is not possible in java.