In this page provide you software multiple choice question which help to many exam like Semester exam, Gate Exam, Railway , ISRO etc.
Java Data Types MCQ SET-1
Q.1 Which of the following is NOT a primitive data type in Java?
Array
Boolean
Char
None of these
Explanation
In Java, primitive data types are predefined by the language (like int, char, boolean). Arrays, Classes, and Interfaces are considered Reference or Non-Primitive data types.
Q.2 How many primitive data types are defined in Java?
7
8
6
None of these
Explanation
Java has 8 primitive data types: byte, short, int, long, float, double, boolean, and char.
Q.3 What is the size of the 'byte' data type in Java?
8 bit
16 bit
None of these
Explanation
A ‘byte’ in Java is an 8-bit signed two’s complement integer.
Q.4 What is the default value of the 'byte' data type in Java?
0
0.0
0.0d
None of these
Explanation
The default value for integer-based primitives (byte, short, int, long) is always 0.
Q.5 What is the default value of the 'float' data type in Java?
0
0.0f
0.0d
None of these
Explanation
The default value for a float is 0.0f. Without the ‘f’ suffix, decimal literals are treated as doubles.
Q.6 What is the size of the 'double' data type in Java?
4 byte
2 byte
8 byte
None of these
Explanation
A ‘double’ is a double-precision 64-bit (8 bytes) IEEE 754 floating point.
Q.7 What is the output of this code snippet? \nint a=5; double d=a; System.out.println(d);
5
5.0
5.0d
None of these
Explanation
This is an example of widening (implicit) conversion. An integer value is automatically converted to a double, resulting in 5.0.
Q.8 What is the memory size of the 'int' data type in Java?
4 byte
8 byte
16 byte
None of these
Explanation
An ‘int’ in Java is a 32-bit signed integer, which occupies 4 bytes of memory.
Q.9 What is the return type of a constructor in Java?
int
char
No return type
None of these
Explanation
Constructors do not have a return type, not even void. Their purpose is to initialize the state of an object.
Q.10 What is the range of the 'byte' data type?
-128 to 127
128 to 127
-32768 to 32767
None of these
Explanation
Since a byte is 8 bits, its range is calculated as -2^7 to (2^7 – 1), which is -128 to 127.
Q.11 What is the memory size of the 'long' data type in Java?
8 byte
4 byte
2 byte
None of these
Explanation
A ‘long’ data type is a 64-bit signed integer, occupying 8 bytes of memory.
Q.12 What is the default value of the 'long' data type in Java?
0
0.0
0.0L
None of these
Explanation
The default value for a long variable is 0L (or simply 0).
Q.13 What is the default value of a variable with the 'boolean' data type?
TRUE
FALSE
null
None of these
Explanation
In Java, the default value for the boolean primitive type is ‘false’.
Q.14 Which of the following represents a correct hierarchy for implicit (widening) conversion?
double, long, int, short, byte
byte, long, int, short, double
double, byte, int, short, long
None of these
Explanation
Implicit conversion occurs when moving from a smaller data type to a larger one (e.g., byte to short to int to long to float to double).
Q.15 Which of the following represents the order typically used for explicit (narrowing) conversion?
double, long, int, short, byte
byte, long, int, short, double
byte, short, int, long, double
None of these
Explanation
Explicit conversion (casting) is required when converting a larger type to a smaller type to prevent data loss.
Q.16 Which of the following is NOT a valid data type in Java?
short
int
long double
None of these
Explanation
Java does not have a ‘long double’ type; this type exists in C/C++. Java uses ‘float’ and ‘double’ for floating-point numbers.
Q.17 What is the size of a 'char' data type in Java?
1 byte
2 bytes
4 bytes
None of these
Explanation
Java uses the Unicode character set, so a ‘char’ occupies 2 bytes (16 bits).
Q.18 What is the range of a 'char' data type constant in Java?
0 to 65535
0 to 65536
0 to 125
None of these
Explanation
A char is a 16-bit unsigned integer representing Unicode characters, so its range is 0 to 65,535.
Q.19 What is the fundamental definition of a variable?
Data container
Variable store
Data
None of these
Explanation
A variable is a container (a reserved area in memory) that holds data to be used during the execution of a program.
Q.20 A variable whose value varies from object to object is known as a(n)?
Global Variable
Local Variable
Instance variable
None of these
Explanation
Instance variables are declared inside a class but outside methods; each object of the class has its own copy of these variables.