Mock QuestionsBill'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?
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?
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.
|