Questions
What is the output?
class sample4 extends Thread {
public static void main(String[] args) {
new sample4().start();
}
public void run() {
try {
System.out.println("Starting to wait");
wait(1000);
System.out.println("Done waiting, returning back");
}
catch(InterruptedException e) {
System.out.println("InterruptedException Found");
}
catch(Exception e) {
System.out.println("Exception found");
}
}
}
- Starting to waitGoes an infinite wait and deadlock
- Starting to waitException found
- Starting to waitDone waiting, returning back
- Starting to waitInterruptedException Found
- None of these
What are wrapper classes?
Java is not purely OOP because of primitive type but then came the concept of wrapper class.
- Classes that allow primitive types to be accessed as objects
- Class that encapsulates the class
- Class that uses polymorphism
- Both 2 and 3
- None of these
Which modifiers may be used with an inner class (non-local), which is a member of an outer class?
Classes use some access specifiers for their accessibilty in other classes or packages.
- Public, protected
- Only public
- Public, protected, private, static, final, or abstract
- Only static
- Public, private, protected, static but not final
Is null a keyword?
Null is generally used as default value for strings. It cannot be taken as a datatype.
- Yes
- No
- Both 1 and 2 (Depends on situation)
- Null is in heap memory.
- None of these
What is the output?
public class sample5 {
public static void main(String[] args) {
String a = "Hi/there";
String n[] =a.split("/");
System.out.print(n[0] + " ");
}
}
- Hi there
- Hi-
- Hi
- there
- None of these