Question 31 Given Following Code Two Service Classes Public Abstract Class Public Public S Q13148639

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 calledn”); }}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 keywordimplements 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 mustprovide the implementation for all direct abstract superclassabstract 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 threeclasses:

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”);
          returnnumber;
     }

     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 codesequence:

     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 threeclasses:

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”);
          returnnumber;
     }

     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 codesequence:

     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 asuperclass method having the same method signature cannot call thatsuperclass method from within the overriding subclass methodbody.

True

False

2.5 points

Question 38

For Question 38 consider the following two classes:

     public abstract class C
     {
          private voidfoo1()
          {
              System.out.println( “Hello foo1” );
          }
          publicabstract void foo2();
          publicabstract int foo3();
          public voidfoo1Call()
          {
              foo1();
          }
     }
     public class D extends C
     {
          public voidfoo2()
          {
              System.out.println( “Hello foo2” );
          }
          public intfoo3()
          {
              return 10;
          }
          private voidfoo4()
          {
              System.out.println( “Hello D foo4()” );
          }
     }

To instantiate an object of class C we could use thefollowing 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 twoclasses:

     public abstract class C
     {
          private voidfoo1()
          {
              System.out.println( “Hello foo1” );
          }
          publicabstract void foo2();
          publicabstract int foo3();
          public voidfoo1Call()
          {
              foo1();
          }
     }
     public class D extends C
     {
          public voidfoo2()
          {
              System.out.println( “Hello foo2” );
          }
          public intfoo3()
          {
              return 10;
          }
          private voidfoo4()
          {
              System.out.println( “Hello D foo4()” );
          }
     }

Which of the following code sequences, if any, willsuccessfully 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 exceptionclass exists and is a subclass of IndexOutofBoundsException, whatis 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!n” );
}

     catch( IndexOutOfBoundsException ie)
{
     System.out.println( ie.getMessage());
}

finally()
{
     System.out.println(“I’d rather besailingn”);
}

a.

OOPS!
A message indicating the cause of the exception thrown
I’d rather be sailing

b.

J
I’d rather be sailing

c.

OOPS!

I’d rather be sailing

d.

J

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *