Java Data Types MCQ

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

Q1) Java has how many primitive data types?

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

View Answer Answer:- 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 stores only one value at a time.
b) Reference data type can store multiple values at a time.
c) Reference data types can store different types of values.
d) None of these

View Answer Answer:- 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

View Answer Answer:- 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 the boolean data type are?

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

View Answer Answer:- 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

View Answer Answer:- 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;

View Answer Answer:- 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

View Answer Answer:- 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 value is considered as which data type?

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

View Answer Answer:- 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

View Answer Answer:- 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;

View Answer Answer:- 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;

View Answer Answer:- b) char ch2 = 97;

Q12) The Java characters are based on?

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

View Answer Answer:- a) Unicode character set

Q13) The default value for all referenced data types?

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

View Answer Answer:- c) null

Q14) Find the output of the below Java program?

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

View Answer Answer:- d) None of these

We can’t store negative value to char data type, it gives compile time error.

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!

Leave a Comment

Your email address will not be published. Required fields are marked *