6
Q:

void waitForSignal() {

Object obj = new Object();

synchronized (Thread.currentThread()) {

obj.wait();

obj.notify();

}

}

Which statement is true?

A) This code can throw an InterruptedException. B) This code can throw an IllegalMonitorStateException.
C) This code can throw a TimeoutException after ten minutes D) All the above

Answer:   B) This code can throw an IllegalMonitorStateException.



Explanation:

It will throw  IllegalMonitorStateException.

Subject: Java
Job Role: IT Trainer
Q:

Which package is imported by default?

Answer java.lang package is imported by default even without a package declaration.
Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 2000
Q:

Can a source file contain more than one class declaration?

Answer Yes a single source file can contain any number of Class declarations but only one of the class can be declared as public.
Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 2670
Q:

Does the order of public and static declaration matter in main() method?

Answer No. It doesn't matter but void should always come before main().
Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 2818
Q:

Can a main() method be declared final?

Answer Yes. Any inheriting class will not be able to have it's own default main() method.
Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 3419
Q:

What is the argument of main() method?

Answer main() method accepts an array of String object as arguement.
Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 2108
Q:

How to define a constant variable in Java?

Answer The variable should be declared as static and final. So only one copy of the variable exists for all instances of the class and the value can't be changed also.
static final int PI = 2.14; is an example for constant.
Report Error

View answer Workspace Report Error Discuss

Subject: Java

1 2834
Q:

Should a main() method be compulsorily declared in all java classes?

Answer No not required. main() method should be defined only if the source class is a java application.
Report Error

View answer Workspace Report Error Discuss

Subject: Java

10 8129
Q:

What is the return type of the main() method?

Answer Main() method doesn't return anything hence declared void.
Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 2150