Java MCQ – Multiple Choice Questions and Answers – Data Types and Variables – Part 2
This collection of Java Multiple Choice Questions and Answers (MCQs): Quizzes & Practice Tests with Answer focuses on “Java data types and variables”.
1. In Java int, short, byte and long all of these are _________
A unsigned
B signed
C Both of the above
D None of these
2. Which of the following is a valid declaration of a boolean?
A boolean b1 = 'true';
B boolean b2 = false;
C boolean b3 = 'false';
D boolean b4 = 1;
3. An expression include byte, int, and numbers is moved up to which of these?
A int
B long
C byte
D float
4. What is the default value of a variable declared boolean?
A TRUE
B FALSE
C null
D 1
5. Which data type(s) can store 64 bit Value?
A boolean
B int
C long
D float
6. Scope of Byte Data Type is ______.
A -128 to 128
B -127 to 127
C -127 to 128
D -128 to 127
7. What is the output of the following code?
public class A { public static void main(String args[]) { int a; a = 10; if(a == 10) { int b = 20; System.out.print("a and b: "+ a + " " + b); b = a*2; } b = 100; System.out.print("a and b: " + a + " " + b); } }
A 10 20 10 100
B 10 20 10 20
C 10 20 10 10
D Error
8. float is represented with ______ and double is represented with ______.
A 32 and 64
B 64 and 64
C 32 and 32
D 64 and 32
9. Which automatic type conversion is feasible?
A long to int
B int to long
C byte to int
D short to int
10. What is the output of the following code?
public class Q10 { static void echo(float x) { System.out.print("float"); } static void echo(double x) { System.out.print("double"); } public static void main(String[] args) { echo(25.5); } }
A double
B float
C Compilation Error
D Exception is thrown at runtime