Question: Answer the Questions(Multiple Choice ): Question 36 For Question 36 consider the following three classes: public class A { private int number; protected String name;

Answer the Questions(Multiple Choice):

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!