Logo

Java Questions Set 132:

Quiz Mode

Can a single machine run multiple JVM instances?

1
2

Solution:

Predict the output of the following Java code.

1
2
3
4

Solution:

What is the output of the following Java code?

1
2
3
4

Solution:

When no catch block is used, which of these handles the exception?

1
2
3
4

Solution:

Which Java interface handles the event when a component is added to a container?

1
2
3
4

Solution:

what should be the output of this code block?

  public class abekus {

    public static void main(String[] args) {

      String input = "";

      System.out.println("-" + input.trim().trim() + "-");

    }

  }

1
2
3
4

Solution:

public class test

{

          public static void main(String[] args)

          {

                 int[] x=new int[5];

                 x[1]='a';

                 System.out.println(x[1]+" "+x[2]);

          }

}

1
2
3
4

Solution:

what should be the output of this code block?

import java.util.*;

class GenericStack < E > {

 Stack < E > stack = new Stack < E > ();

 public void push(E obj) {

  stack.push(obj);

 }

 public E pop() {

  E obj = stack.pop();

  return obj;

 }

}

public class Test {

 public static void main(String args[]) {

  GenericStack < String > gs = new GenericStack < String > ();

  gs.push("Hello");

  System.out.print(gs.pop() + " ");

  GenericStack < Integer > gs = new GenericStack < Integer > ();

  gs.push(44);

  System.out.println(gs.pop());

 }

}

1
2
3
4

Solution:

import java.time.LocalDateTime

import java.time.format.DateTimeFormatter

public class LDT{

 public static void main(String[] args){

  LocalDateTime datetime1 LocalDateTime.of(2017,1,14,10,34);

  LocalDateTime datetime2 datetime1.plusDays(120);

  System.out.println("Before Formatting: datetime2);

  DateTimeFormatter format DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm");

  String formatDateTime datetime2.format(format);

  System.out.println("After Formatting:" + formatDateTime);

 }

}

1
2
3
4

Solution: