Data Types And Variables(Computer Science > Java Program ) Questions and Answers
Question 1. Java is a ........... language.
weakly typed
strongly typed
moderate typed
None of these
Explanation:-
Answer: Option B. -> strongly typed
Question 2. In Java byte, short, int and long all of these are
signed
unsigned
Both of the above
None of these
Explanation:-
Answer: Option A. -> signed
Question 3. How many primitive data types are there in Java?
6
7
8
9
Explanation:-
Answer: Option C. -> 8
Question 4. Size of int in Java is
16 bit
32 bit
64 bit
Depends on execution environment
Explanation:-
Answer: Option B. -> 32 bit
Question 5. The smallest integer type is ......... and its size is ......... bits.
short, 8
byte, 8
short, 16
short, 16
Explanation:-
Answer: Option B. -> byte, 8
Question 6. Size of float and double in Java is
32 and 64
64 and 64
32 and 32
64 and 32
Explanation:-
Answer: Option A. -> 32 and 64
Question 7. Automatic type conversion in Java takes place when
Two type are compatible and size of destination type is shorter than source type.
Two type are compatible and size of destination type is equal of source type.
Two type are compatible and size of destination type is larger than source type.
All of the above
Explanation:-
Answer: Option C. -> Two type are compatible and size of destination type is larger than source type.
Question 8. Determine output: class A{ public static void main(String args[]){ int x; x = 10; if(x == 10){ int y = 20; System.out.print("x and y: "+ x + " " + y); y = x*2; } y = 100; System.out.print("x and y: " + x + " " + y); } }
10 20 10 100
10 20 10 20
10 20 10 10
Error
Explanation:-
Answer: Option D. -> Error
Question 9. Which of the following automatic type conversion will be possible?
short to int
byte to int
int to long
long to int
Explanation:-
Answer: Option C. -> int to long
Question 10. What is the output of the following program? class A{ public static void main(String args[]){ byte b; int i = 258; double d = 325.59; b = (byte) i; System.out.print(b); i = (int) d; System.out.print(i); b = (byte) d; System.out.print(b); } }