Programming in Java

Programming in Java

5 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

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");
}
}
}

  1. Starting to waitGoes an infinite wait and deadlock
  2. Starting to waitException found
  3. Starting to waitDone waiting, returning back
  4. Starting to waitInterruptedException Found
  5. None of these
Question 2 Multiple Choice (Single Answer)

What are wrapper classes?

Java is not purely OOP because of primitive type but then came the concept of wrapper class.

  1. Classes that allow primitive types to be accessed as objects
  2. Class that encapsulates the class
  3. Class that uses polymorphism
  4. Both 2 and 3
  5. None of these
Question 3 Multiple Choice (Single Answer)

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.

  1. Public, protected
  2. Only public
  3. Public, protected, private, static, final, or abstract
  4. Only static
  5. Public, private, protected, static but not final
Question 4 Multiple Choice (Single Answer)

Is null a keyword?

Null is generally used as default value for strings. It cannot be taken as a datatype.

  1. Yes
  2. No
  3. Both 1 and 2 (Depends on situation)
  4. Null is in heap memory.
  5. None of these
Question 5 Multiple Choice (Single Answer)

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] + " ");
}
}

  1. Hi there
  2. Hi-
  3. Hi
  4. there
  5. None of these