Alien head

Java Programming Language Quiz - 5

Description: Java Programming Language Quiz - 5
Number of Questions: 10
Created by:
Tags: java

HashMap is thread-safe whereas Hashtable is not10, Which of the following assignment statements is invalid?

  1. double D = 45456.444;

  2. long L = 45784;

  3. int I = L;

  4. int J = (int) D;

Answer: 3

Assume the following method is properly synchronized and called from a thread A on an object B: wait(2000); After calling this method, when will the thread A become a candidate to get another turn at the CPU?

  1. After object B is notified, or after two seconds

  2. After the lock on B is released, or after two seconds

  3. Two seconds after object B is notified

  4. Two seconds after lock B is released.

Answer: 1

for(Object obj: expression) { } What interface must the ?expression? implement in order for you to use it with enhanced for loop construct?

  1. Iterator

  2. Map

  3. Enumeration

  4. Iterable

Answer: 4

Which of the following are primitive types?

  1. Float

  2. None of the above

  3. byte

  4. String

  5. integer

Answer: 3

What will happen when you attempt to compile and run the following code


public class Hope{
    public static void main(String argv[]){
        Hope h = new Hope();
    }
    protected Hope(){
        for(int i =0;
        i <10;
        i ++){
            System.out.println(i);
        }
    }
}
  1. Compilation and running with output 0 to 9

  2. Run time error: Constructors cannot be declared protected

  3. Compilation error: Constructors cannot be declared protected

  4. Compilation and running with output 0 to 10

  5. None of the above

Answer: 1

What is output of the above program?

Class conditional {
 public static void main(String args[]) {
  int i = 20;
  int j = 55;
  int z = 0;
  z = i < j ? i : j; // ternary operator
  System.out.println("The value assigned is " + z);
 }
}
  1. 20

  2. 55

  3. None of the above

Answer: 1

A class cannot be declared:

  1. Static

  2. Private

  3. Default

  4. None of the above

Answer: 2

Following code will result in:

int a1 = 5; 
double a2 = (float)a1;
  1. Compilation error

  2. Runtime error

  3. No errors

  4. Execptions

Answer: 3

Following code will result in:

class A {
  int b = 1;
  public static void main(String [] args) {
       System.out.println("b is " + b);
 }
}
  1. Compilation error

  2. Runtime Error

  3. Runtime Exception

  4. Output of b is 1

Answer: 1

Following code will result in:

class A { 
   public static void main(String [] args) {
       B b = new A(); 
   }
} 
class B extends A {}
  1. Compilation error

  2. Runtime Error

  3. Runtime Exception

  4. Other Execptions

Answer: 1
+ View questions