Java Data Types Quiz

Java Data Types Quiz | Find the correct answer for below question | Recommended Reading:- Data types in Java, Float and double data type in Java

Q1) Java have how many primitive data types?

a) 7
b) 8
c) 9
c) None of these


Ans:- b) 8
Java primitive data types are:- byte, short, int, long, float, double, char, boolean.

Q2) Which of the following is false?

a) Primitive data type store only one value at a time.
b) Reference data type can store multiple values at a time.
c) Reference data type can store different types of values.
d) None of these


Ans:- d) None of these
All statements are true.

Q3) In Java, the size of the char data type is?

a) 1 bit
2) 7 bits
3) 1 byte
4) 2 bytes


Ans:- 4) 2 bytes
Java characters are Unicode character set based and it ranges from 0 to 65535. Hence to store these values 2 bytes of memory is required.

Q4) The allowed values for boolean data type is,

a) True
b) False
c) true
d) null


Ans:- c) true
The true and false are Java boolean literals and they are in lowercase.

Q5) Integer zero (0) is not the default value of which data type?

a) double
b) byte
c) short
d) long


Ans:- a) double
The default value for double data type is 0.0, not 0.

Q6) Which of the following is valid?

a) byte b1 = 128;
b) byte b1 = ‘a’;
c) byte b1 = 9.9;
d) byte b1 = false;


Ans:- b) byte b1 = ‘a’;

Q7) In Java size of int data type is?

a) 2 bytes in 16-bit processor
b) 4 bytes in 16-bit/32-bit processor
c) 4 bytes in all systems
d) None of these


Ans:- c) 4 bytes in all systems
Java is plateform independent programming language. The size of data types are fixed.

Q8) In Java by default every integer values is considered as which data type?

a) byte
b) int
c) long
d) double


Ans:- b) int

Q9) Which of the following is false?

a) double d = 97.5d;
b) double d = 97.5D;
c) double d = 97.5F;
d) None of these


Ans:- d) None of these
To represent double ‘d’ or ‘D’ prefix is optional. Double can store all its lesser range/precision value.

Q10) Which of the following is invalid?

a) float f1 = 10;
b) float f2 = ‘a’;
c) float f3 = 9.9;
d) float f4 = 9.5F;


Ans:- c) float f3 = 9.9;

Q11) Which of the following is valid?

a) char ch1 = true;
b) char ch2 = 97;
c) char ch3 = 65536;
d) char ch4 = 97.0;


Ans:- b) char ch2 = 97;

Q12) Java characters are based on?

a) Unicode character set
b) ASCII value
c) Both
d) None of these


Ans:- a) Unicode character set

Q13) The default value for all referenced data type?

a) 0
b) 0.0
c) null
d) false


Ans:- c) null

Q14) Find the output?

class Test{
   public static void main(String[] args) {
      char ch1 = 97;
      char ch2 = -98;
      System.out.println(ch1+".."+ch2);
   }
}

a) 97..98
b) a..b
c) a..-b
d) None of these


Ans:- d) None of these
We can’t store negative value to char data type, it gives compile time error.

Please write comments if you find anything incorrect, or you want to share more information about Java Data Types Quiz.


Leave a Reply