Logo

Java Questions Set 100:

Quiz Mode

What keyword is used to declare an interface in Java?

1
2
3
4

Solution:

A variable declared as private x = 214; can be accessed _____?

1
2
3
4

Solution:

Which class has the ability to catch all exceptions that cannot be handled by Exception handling mechanisms.

1
2
3
4

Solution:

Statement 1 - JAVA_HOME  is used to set java path 

Statement 2 - JAVA is used to set java path

1
2
3
4

Solution:

Which of the following statements about JUnit is false?

1
2
3
4

Solution:

What will be the output of the following Java code?


class IsinfiniteOutput

{

public static void main(String[] args)

{

Double d = new Double(1 / 0.0);

boolean x = d.isInfinite();

System.out.print(x);

}

}

1
2
3
4

Solution:

 

What will be the output of the program? 


public class Test
{
   private static int[] x;
   public static void main(String[] args)
   {
       System.out.println(x[0]);
   }
}

1
2
3
4

Solution:

Statement 1- previous() of ListIterator used to obtain an index of previous element 

Statement 2- back() of ListIterator used to obtain an index of previous element

Statement 3- GoBack() of ListIterator used to obtain an index of previous element

Statement 4- previousIndex() of ListIterator used to obtain an index of previous element 

 



1
2
3
4

Solution:

Predict the output of the following Java code:

class Seller {

int value = 10000;

synchronized void cost(int value) {

System.out.println("Spend value");

if (this.value < value) {

System.out.println("Less value");

try {

wait();

} catch (Exception e) {}

}

this.value = this.value - value;

System.out.println("process completed");

}

synchronized void paid(int value) {

System.out.println("get value");

this.value = this.value + value;

System.out.println("completed");

notify();

}

}

public class Main {

public static void main(String args[]) {

Seller c = new Seller();

new Thread() {

public void run() {

c.cost(15000);

}

}.start();

new Thread() {

public void run() {

c.paid(10000);

}

}.start();

}

}

1
2
3
4

Solution: