Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Answer them all Question 31 Given the following code for two service classes: public abstract class A { public A(){} public A(String x) { System.out.println(x

Answer them all

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

2.5 points

Question 36

For Question 36 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 b4 = new B(); System.out.println( b4.foo3() );

a.

A() called B() called A version of foo2() called Hi B version of foo2() called

b.

A() called B() called A version of foo3() called B version of foo3() called Hi foo3

c.

A() called B() called A version of foo3() called B version of foo3() called

d.

A() called B() called Hi foo3

2.5 points

Question 37

True or False, a method from a subclass that overrides a superclass method having the same method signature cannot call that superclass method from within the overriding subclass method body.

True

False

2.5 points

Question 38

For Question 38 consider the following two classes: public abstract class C { private void foo1() { System.out.println( Hello foo1 ); } public abstract void foo2(); public abstract int foo3(); public void foo1Call() { foo1(); } } public class D extends C { public void foo2() { System.out.println( Hello foo2 ); } public int foo3() { return 10; } private void foo4() { System.out.println( Hello D foo4() ); } }

To instantiate an object of class C we could use the following statement(s):

a.

C c2; c2 = new C();

b.

C c2 = new C();

c.

a or b

d.

none of the above

2.5 points

Question 39

For Question 39 consider the following two classes: public abstract class C { private void foo1() { System.out.println( Hello foo1 ); } public abstract void foo2(); public abstract int foo3(); public void foo1Call() { foo1(); } } public class D extends C { public void foo2() { System.out.println( Hello foo2 ); } public int foo3() { return 10; } private void foo4() { System.out.println( Hello D foo4() ); } }

Which of the following code sequences, if any, will successfully access private method foo1 in class C?

a.

C c2 = new C(); c2.foo1();

b.

C c2 ; c2 = new D(); c2.foo1();

c.

D d1 = new D(); d1.foo1();

d.

C c1 = new D(); c1.foo1Call();

e.

None of the above

2.5 points

Question 40

Assuming a StringIndexOutOfBoundsException exception class exists and is a subclass of IndexOutofBoundsException, what is the output of this code sequence? try { String word = new String("avaJ"); System.out.println( word.charAt( 3 ) ); } catch( StringIndexOutOfBoundsException e ) { System.out.println( OOPS! ); } catch( IndexOutOfBoundsException ie ) { System.out.println( ie.getMessage() ); } finally() { System.out.println("Id rather be sailing "); }

a.

OOPS! A message indicating the cause of the exception thrown Id rather be sailing

b.

J Id rather be sailing

c.

OOPS! Id rather be sailing

d.

J

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

T Sql Window Functions For Data Analysis And Beyond

Authors: Itzik Ben Gan

2nd Edition

0135861446, 978-0135861448

More Books

Students also viewed these Databases questions

Question

Explain all drawbacks of application procedure.

Answered: 1 week ago

Question

Explain the testing process of accounting 2?

Answered: 1 week ago

Question

Draft a proposal for a risk assessment exercise.

Answered: 1 week ago