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