Question
Answer the Questions(Multiple Choice ): Question 31 Given the following code for two service classes: public abstract class A { public A(){} public A(String x)
Answer the Questions(Multiple Choice):
Question 31
Given the following code for two service classes: public abstract class A { public A(){} public A(String x) { System.out.println(x + " Overloaded constructor for class A called "); } } public class B extends A { public B() { super("Hello"); } public B(String i) { super(i); } } And given the following code for the application class: public class App { public static void main(String[] args) { B b = new B(); System.out.println("Hello Again "); } } What would the output be when the application class is executed?
a. | Nothing is output | |
b. | Hello Overloaded constructor for class A called Hello Again | |
c. | Hello Again | |
d. | 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
a. | An abstract class | |
b. | One direct superclass only | |
c. | An interface | |
d. | 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
For Question 34 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 b2 = new B(); b2.foo1();
a. | A() called B() called A version of foo1() called | |
b. | A() called B() called A version of foo1() called B version of foo1() called | |
c. | A() called B() called B version of foo1() called | |
d. | 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. | A() called B() called A version of foo2() called B version of foo2() called | |
b. | A() called B() called A version of foo2() called B version of foo2() called 5 | |
c. | A() called B() called B version of foo2() called 5 | |
d. | B() called A() called B version of foo2() called |
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