Java Data Types

Last Updated :
Discuss
Comments

Question 1

What is the default value of a boolean in Java?

  • A

    true

  • B

    false

  • C

    null

  • D

    0

Question 2

Which data type is best for storing the ASCII value of a character?

  • A

    char

  • B

    byte

  • C

    int

  • D

    short

Question 3

What will be the output of this code?

Java
int a = 7;
double b = 2;
System.out.println(a / b);
  • A

    3

  • B

    3.5

  • C

    3.0

  • D

    Error

Question 4

Which of the following is a valid declaration of a float data type?

  • A

    float f = 10.5;

  • B

    float f = 10.5f;

  • C

    float f = "10.5";

  • D

    float f = (10.5);

Question 5

What will be the output of this code?

Java
byte x = 127;
x++;
System.out.println(x);
  • A

    128

  • B

    127

  • C

    -128

  • D

    Compilation Error

Question 6

Which of the following combinations will NOT compile?

  • A

    long l = 100L;

  • B

    int i = 10000000000;

  • C

    double d = 1.2e3;

  • D

    short s = 100;

Question 7

What is the size of the char type in Java?

  • A

    8 bits

  • B

    32 bits

  • C

    16 bits

  • D

    Depends on the platform

Question 8

What will be printed by the following code?

Java
float f = 5.6f;
int i = (int) f;
System.out.println(i);
  • A

    Compilation Error

  • B

    5.6

  • C

    6

  • D

    5

Question 9

What is the result of this code?

Java
int a = 1_000_000;
float b = a;
System.out.println(b == a);
  • A

    true

  • B

    false

  • C

    Compilation Error

  • D

    Runtime Error

Question 10

What will be the output of the following code?

Java
long l = 2147483648L;
int i = (int) l;
System.out.println(i);
  • A

    2147483648

  • B

    -2147483648

  • C

    Overflow

  • D

    Compilation Error

There are 10 questions to complete.

Take a part in the ongoing discussion