Java AWT Base

 


1. What is the correct ordering for the import, class and package declarations when found in a single file?

A.  package, import, class

B.  class, import, package

C.  import, package, class

D.  package, class, import

2. Which of the following is correct:

A.  String temp [] = new String {"j" "a" "z"};

B.  String temp [] = { "j " " b" "c"};

C.  String temp = {"a", "b", "c"};

D.  String temp [] = {"a", "b", "c"};

3. What is the correct declaration of an abstract method that is intended to be public:

A.  public abstract void add();

B.  public abstract void add() {}

C.  public abstract add();

D.  public virtual add();

4. Which of the following methods are defined on the Graphics class:

A.  drawLine(int, int, int, int)

B.  drawImage(Image, int, int, ImageObserver)

C.  drawString(String, int, int)

D.  add(Component);

E.   setVisible(boolean);

F.   setLayout(Object);

 

Select all correct answers.

5. Using a FlowLayout manager, which is the correct way to add elements to a container:

A.  add(component);

B.  add("Center", component);

C.  add(x, y, component);

D.  set(component);

6. In order to cause the paint(Graphics) method to execute, which of the following is the most appropriate method to call:

A.  paint()

B.  repaint()

C.  paint(Graphics)

D.  update(Graphics)

E.   None – you should never cause paint(Graphics) to execute

7 Given the following sequence of Java statements

 StringBuffer sb = new StringBuffer("abc");

1. String s = new String("abc");

2. sb.append("def");

3. s.append("def");

4. sb.insert(1, "zzz");

5. s.concat(sb);

6.   s.trim(); 

Which of the following statements are true:

A.  The compiler would generate an error for line 1.

B.  The compiler would generate an error for line 2.

C.  The compiler would generate an error for line 3.

D.  The compiler would generate an error for line 4.

E.   The compiler would generate an error for line 5.

F.   The compiler would generate an error for line 6.

G.  The compiler would generate an error for line 7.

8 What is the result of executing the following Java class:

 import java.awt.*;

 public class FrameTest extends Frame {

public FrameTest() {

add (new Button("First"));

add (new Button("Second"));

add (new Button("Third"));

pack();

setVisible(true);

}

public static void main(String args []) {

new FrameTest();

}

}

 Select from the following options: 

A.  Nothing happens.

B.  Three buttons are displayed across a window.

C.  A runtime exception is generated (no layout manager specified).

D.  Only the "first" button is displayed.

E.   Only the "second" button is displayed.

F.   Only the "third" button is displayed.

10. Consider the following code sample:

class Tree{}

class Pine extends Tree{}

class Oak extends Tree{}

public class Forest

{  public static void main( String[] args )

   {  Tree tree = new Pine();

 

      if( tree instanceof Pine )

      System.out.println( "Pine" );

 

      if( tree instanceof Tree )

      System.out.println( "Tree" );

 

      if( tree instanceof Oak )

      System.out.println( "Oak" );

 

      else System.out.println( "Oops" );

   }

}

Select all choices that will be printed:
a) Pine
b) Tree
c) Forest
d) Oops
e) (nothing printed)

 

11 ) 

class Z {

  void m1() {

    abstract class A {}      // 1

    final class B {}         // 2

    private class C {}       // 3

    protected class D {}     // 4

    public class E {}        // 5

  }

}

Which class declarations result in compile-time errors?

a. 

1

b. 

2

c. 

3

d. 

4

e. 

5