Question 1.

We have the following organization of classes.

class Parent { }
class DerivedOne extends Parent { }
class DerivedTwo extends Parent { }

Which of the following statements is correct for the following expression.

Parent p = new Parent();
DerivedOne d1 = new DerivedOne();
DerivedTwo d2 = new DerivedTwo();
p = d1;

  1. llegal both compile and runtime,
  2. Legal at compile time, but fails at runtime,
  3. Legal at compile and runtime
Question 2.

We have the following organization of classes.

class Parent { }
class DerivedOne extends Parent { }
class DerivedTwo extends Parent { }

Which of the following statements is correct for the following expression.

Parent p = new Parent();
DerivedOne d1 = new DerivedOne();
DerivedTwo d2 = new DerivedTwo();
d1 = d2;

  1. llegal both compile and runtime,
  2. Legal at compile time, but fails at runtime,
  3. Legal at compile and runtime
Question 3.

We have the following organization of classes.

class Parent { }
class DerivedOne extends Parent { }
class DerivedTwo extends Parent { }

Which of the following statements is correct for the following expression.

Parent p = new Parent();
DerivedOne d1 = new DerivedOne();
DerivedTwo d2 = new DerivedTwo();
d1 = (DerivedOne)d2;

  1. llegal both compile and runtime,
  2. Legal at compile time, but fails at runtime,
  3. Legal at compile and runtime
Question 4.

We have the following organization of classes.

class Parent { }
class DerivedOne extends Parent { }
class DerivedTwo extends Parent { }

Which of the following statements is correct for the following expression.

Parent p = new Parent();
DerivedOne d1 = new DerivedOne();
DerivedTwo d2 = new DerivedTwo();
d1 = (DerivedOne)p;

  1. llegal both compile and runtime,
  2. Legal at compile time, but fails at runtime,
  3. Legal at compile and runtime
Question 5.

We have the following organization of classes.

class Parent { }
class DerivedOne extends Parent { }
class DerivedTwo extends Parent { }

Which of the following statements is correct for the following expression.

Parent p = new Parent();
DerivedOne d1 = new DerivedOne();
DerivedTwo d2 = new DerivedTwo();
p = (Parent)d1;

  1. llegal both compile and runtime,
  2. Legal at compile time, but fails at runtime,
  3. Legal at compile and runtime
Question 6.

With which I/O operation can we append. update a file?

  1. RandomAccessFile(),
  2. OutputStream()
  3. DataOutputStream()
Question 7.

For which of the following code will produce ‘test” as output on the screen?

  1. int x=10.0;
    if ( x==10.0) { System.out.println(“test”); }
  2. int x=012;
    if ( x==10.0) { System.out.println(“test”); }
  3. int x=10f;
    if ( x==10.0) { System.out.println(“test”); }
  4. int x=10L;
    if ( x==10.0) { System.out.println(“test”); }
Question 8.

Given this class?

class Loop {
public static void main( String [] agrs) {
int x=0; int y=0;
outer: for (x=0; x<100;x++) {
middle: for (y=0;y<100;y++) {
System.out.println("x=" + x + "; y=" + y);
if (y==10) { <<<insert code>>> } } }
} //main
} //class

The question is which code must replace the <<>> to finish the outerloop?

  1. continue middle;
  2. break outer;
  3. break middle;
  4. continue outer;
  5. none of these...
Question 9.

Which component cannot be added to a container?

  1. Component

  2. Menu

  3. Container

  4. Applet

  5. Button
Question 10.

What does it mean when the handleEvent() returns the true boolean?

  1. the event will be handled by the component,

  2. the action() method will handle the event,

  3. the event will be handled by the super.handleEvent()

  4. do nothing

 


DISCLAIMER