Answer the Questions(Multiple Choice ): Question 39 For Question 39 consider the
ID: 3861127 • Letter: A
Question
Answer the Questions(Multiple Choice):
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?
C c2 = new C();
c2.foo1();
C c2 ;
c2 = new D();
c2.foo1();
D d1 = new D();
d1.foo1();
C c1 = new D();
c1.foo1Call();
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("I’d rather be sailing ");
}
OOPS!
A message indicating the cause of the exception thrown
I’d rather be sailing
J
I’d rather be sailing
OOPS!
I’d rather be sailing
J
a.C c2 = new C();
c2.foo1();
C c2 ;
c2 = new D();
c2.foo1();
D d1 = new D();
d1.foo1();
C c1 = new D();
c1.foo1Call();
None of the above
Explanation / Answer
Question 39: Option E none of the above,
Explanation:
As the foo1() method in class C is declared as private, it can't be accessed by any variable which is outside the class. Here in all the options methods outside the class are trying to access foo1() method. Son none of the option is true.
Question 40: Option b.
Explanation: In the above code String word= "avaJ", which means world length is 3;
Therefore word.charAt(3) = 'J'. So J is printed in the first line.
And finally is executed compulsarily, So I’d rather be sailing is printed.