Java quiz questions

Java interview questions

  • 1.

    What will be printed?

    boolean value = Double.NaN == Double.NaN;
    System.out.println(value);
    1. true

    2. false

    Answer
  • 2.

    What will be printed?

    boolean value = -0.0 == 0.0;
    System.out.println(value);
    1. true

    2. false

    Answer
  • 3.

    What will be printed?

    double value = -0.0;
    System.out.println(value);
    1. -0.0

    2. 0

    3. 0.0

    4. -0

    5. NaN

    Answer
  • 4.

    What will be printed?

    int i = 255;
    byte b = (byte) i;
    System.out.println(b);
    1. 255

    2. -1

    3. NaN

    4. -255

    5. -127

    Answer
  • 5.

    What is wrong with this code?

    public String readLine() {
        try {
          BufferedReader br = 
             new BufferedReader(new FileReader("file.txt"));
          String line = br.readLine();
          br.close();
          return line;
        } catch (Exception e) {
          throw new RuntimeException(e);
        }
    }
    1. exception is not declared

    2. more specific exception type must be used in catch

    3. potential resource leak

    4. return must be outside of the try block

    Answer
  • 6.

    What is the outcome?

    int value = (int) 2.0 / 3.0;
    System.out.println(value);
    1. 0

    2. 1

    3. 0.0

    4. Type mismatch: cannot convert from double to int

    Answer
  • 7.

    What will be printed?

    double value = 2 / 3;
    System.out.println(value);
    1. 0

    2. 0.0

    3. 0.6666666666666666

    4. 1

    5. 1.0

    Answer

© 2017 QuizBucket.org