Site hosted by Angelfire.com: Build your free website today!
 

Mock Questions

Bill's Java Certification Resources

class X {
    static private int count = 0;
    public String name;
    int number;
    static synchronized int add() {
        count++;
        name = "I am #" + count;
        return count;
    }
    public X() {
        number = add();
    }
}

What will happened when we try to compile the class and use multiple X object in the program?

  • The class compiled and each X object will get a unique name and number reflecting the order in which it were created.

  • The compiler object to line 7.

  • A runtime error occurs in the add() method.

class X {
    static public int getNum(String s) {
        try {
            String tmp = s.substring(0, s.indexOf(','));
            return Integer.parseInt(tmp);
        } catch (NumberFormatException e) {
            System.out.println("Problem in " + tmp);
        }
        return -1;
    }
    public static void main(String[] args) {
        System.out.println(getNum("123test"));
    }
}

The method getNum is designed to parse and return and integer from an input string which is expected to look like "nnn,XYZ";

What happens when we try to compile this code and execute the program?

  • A compiler error in line 7 prevents compilation.

  • The method prints the error message to standard output and return -1.

  • A NullPointerException is thrown in line 4.

  • A StringIndexOutOfBoundsException is thrown in line 4.

int evtCt = 0;
AWTEvent lastE;
public void saveEvent(AWTEvent evt) {
  lastE = evt;
  evtCt++;
}

Which of the following calls of saveEvent would run without causing an exception? Select all which are correct.

  • call with an AWTEvent object reference

  • call with an ActionEvent object reference

  • call with an EventObject object reference

  • call with null value