Answer the Questions(Multiple Choice ): Question 31 Nothing is output Hello Over
ID: 3860740 • Letter: A
Question
Answer the Questions(Multiple Choice):
Question 31
Nothing is output
Hello Overloaded constructor for class A called
Hello Again
Hello Again
Overloaded constructor for class A called
Hello Again
2.5 points
Question 32
Java, multiple inheritance is implemented with the keyword implements using the concept of
An abstract class
One direct superclass only
An interface
Multiple inheritance is not supported in Java
2.5 points
Question 33
A non abstract subclass extending an abstract superclass must provide the implementation for all direct abstract superclass abstract methods.
True
False
2.5 points
Question 34
A() called
B() called
A version of foo1() called
A() called
B() called
A version of foo1() called
B version of foo1() called
A() called
B() called
B version of foo1() called
A() called
B() called
B version of foo1() called
A version of foo1() called
2.5 points
Question 35
For Question 35 consider the following three classes:
public class A
{
private int number;
protected String name;
public double price;
public A()
{
System.out.println( "A() called");
}
private void foo1()
{
System.out.println( "A version of foo1() called");
}
protected int foo2()
{
System.out.println( "A version of foo2() called");
return number;
}
public String foo3()
{
System.out.println( "A version of foo3() called");
return "Hi";
}
}
public class B extends A
{
private char service;
public B()
{
super();
System.out.println( "B() called" );
}
public void foo1()
{
System.out.println( "B version of foo1() called");
}
protected int foo2()
{
int n = super.foo2();
System.out.println( "B version of foo2() called");
return ( n + 5 );
}
public String foo3()
{
String temp = super.foo3();
System.out.println( "B version of foo3() called");
return ( temp + " foo3");
}
}
public class C extends B
{
public C()
{
super();
System.out.println( "C() called");
}
public void foo1()
{
System.out.println( "C version of foo1() called");
}
}
What is the output of the following code sequence:
B b3 = new B();
int n = b3.foo2();
A() called
B() called
A version of foo2() called
B version of foo2() called
A() called
B() called
A version of foo2() called
B version of foo2() called
5
A() called
B() called
B version of foo2() called
5
B() called
A() called
B version of foo2() called
Nothing is output
b.Hello Overloaded constructor for class A called
Hello Again
Hello Again
d.Overloaded constructor for class A called
Hello Again
Explanation / Answer
Question 31)
Ans : b
main method calls non parameterized constructor of class B which in turn calls super class parameterized constructor with "Hello" as parameter
so it first prints
Hello Overloaded constructor for class A called
and then Hello Again of main class
Question 32)
Ans: c
java doesnot support multiple inheritance that is where inheritance came into picture where we can implement multiple interfaces
Question 33)
Ans: True
Question 34)
Ans: c
main method calls non parameterized constructor of class B which in turn calls super class non parameterized constructor so "A() called" is printed and statement next to calling super class constructor is called hence prints "B() called"
main method calls foo1 method of class B on b2 object which prints "B version of foo1() called"
Question 35)
Ans: a
main method calls non parameterized constructor of class B which in turn calls super class non parameterized constructor so "A() called" is printed and statement next to calling super class constructor is called hence prints "B() called"
main method calls foo2 method of class B on b3 object which calls super class foo2 method which prints "A version of foo2() called" statement next to calling super class foo2 method prints "B version of foo2() called"