MCQ1 1 Datatypes
MCQ1 1 Datatypes
1. Find Output
class Main {
public static void main(String args[]) {
int t;
System.out.println(t);
}
}
A) 0
B) garbage value
C) compiler error
D) runtime error
Answer:
C
2. Predict the output
class Test {
public static void main(String[] args) {
for(int i = 0; 0; i++)
{
System.out.println("Hello");
break;
}
}
}
A) Hello
B) Empty Output
C) Compiler error
D) Runtime error
Ans:
C
3. Predict the output
class Test {
public static void main(String[] args) {
Double object = new Double("2.4");
int a = object.intValue();
byte b = object.byteValue();
float d = object.floatValue();
double c = object.doubleValue();
System.out.println(a + b + c + d ); }
}
A) 8
B) 8.8
C) 8.800000095367432
D) Compilation error
Ans:
C
4. Find output
class variable_scope {
public static void main(String args[]) {
int x;
x = 5;
{
int y = 6;
System.out.print(x + " " + y);
}
System.out.println(x + " " + y); }
}
a) 5 6 5 6
b) 5 6 5
c) Runtime error
d) Compilation error
Answer: d
5. Find output
public class Main {
public static void main(String[] args)
{
byte b = 130;
System.out.println(b);
}
}
a) 130
b) Compilation error
c) Runtime error
d) No output
Ans:
b
6. Find output
public class Main {
public static void main(String[] args)
{
byte b = (byte)345;
System.out.println(b);
}
}
a) 345
b) 89
c) Compilation error
d) Runtime error
Output
b
7. Find output
public class Main {
public static void main(String[] args)
{
byte b = (byte)241;
System.out.println(b);
}
}
a) 241
b) 15
c) -15
d) Compilation error
Ans) c
8. Find output
public class Main {
public static void main(String[] args)
{
int i = 100;
System.out.println((char)i);
}
}
a) 100
b) Compilation error
c) No output
d) d
Ans:
d
9. Find output
int six = 06;
int seven = 07;
int eight = 010;
int nine = 011;
System.out.println("six="+six);
System.out.println("seven="+seven);
System.out.println("eight = " + eight);
System.out.println("nine = " + nine);
Output
six=6
seven=7
eight = 8
nine = 9
10. Find output
int x = 0X0001;
int y = 0x24;
int z = 0xaB;
System.out.println("x = " + x + " y = " + y + " z = "
+ z);
Output
x = 1 y = 36 z = 171
11. Find output
float f = 23.46789;
double d = 1874.1234567;
System.out.println("f="+f+" d="+d);
Output
Compile time error
12. Find output
boolean x = "true", y = "false";
System.out.println(x+" "+y);
Output
Compile time error
13. Find output
char c = '\"';
char d = '\n';
System.out.println(c+" "+d);
Output
Ans:
"
New line
14. Find output
int x = 3957.229;
System.out.println(x);
Output
• Compile time error
15. Find output
byte a = 128;
System.out.println(a);
Output
• Compile time error
16. Find output
byte a = (byte)128;
System.out.println(a);
Output
-128
17. Find output
int year;
System.out.println(year);
Output
• Compilation error
18.Find output
public class Three {
public static void main(String[] args) {
float f = 23.46789;
double d = 1874.1234567;
System.out.println("f="+f+" d="+d);
}
}
Output
• Compilation error
19. Find output
Automatic type conversion in Java takes place
when?
1) Two type are compatible and size of
destination type is shorter than source type.
2) Two type are compatible and size of
destination type is equal of source type
3) Two type are compatible and size of
destination type is larger than source type
4) All of the above
Output
3
20. Find output
public class Test {
public static void main(String[] args) {
int Integer = 123;
char String = 'R';
System.out.println(Integer + " "+ String);
}
}
Output
a) Compilation error
b) Runtime error
c) 123 R
d) No output
Ans:
C
21. Find output
public class Test {
public static void main(String[] args) {
short a=5;
a=a*3;
System.out.println(a);
}
}
Output
• Compilation error
22. Find output
public class Test {
static boolean isMarried;
public static void main(String[] args) {
System.out.println(isMarried);
}
}
Output
false
23. Find output
public class Test {
public static void main(String[] args) {
float f = (1/4)*10;
int i = Math.round(f);
System.out.println(i);
}
}
Output
a) 0
b) 2.5
c) 25
d) 250
Ans:
a
24. Find output
public class Test {
public static void main(String[] args) {
int _rs7;
float $8;
byte _6;
short _$RS3;
}
}
Output
a) Compilation error
b) Runtime error
c) No output
d) 0 00 0
Ans:
c
25. Find output
Size of byte is
a) -32768 to 32767
b) -128 to 127
c) 0 to 255
d) 0 to 65535
Output
B
26. Find output
which statement is used to find int max range
a) int.max
b) Int.maxvalue
c) Integer.MAX_VALUE
d) None of these
Output
• C
27. Find output
Which of the following is smallest integer data
type ?
A. int
B. byte
C. short
D. long
Output
B
28. Find output
Which of the following is not a primitive data
type ?
A. byte
B. enum
C. short
D. int
Output
B
29. Find output
Character data type cannot store following
value.
A. Digit
B. Letter
C. Special Character
D. String
Output
D
30. Find output
Default value of variable having boolean data
type is ___________.
A. true
B. false
C. null
D. Garbage value
Output
• B
31. Find output
class area {
public static void main(String args[]) {
double r, pi, a;
r = 9.8;
pi = 3.14;
a = pi * r * r;
System.out.println(a);
}
}
Output
A. 301.5656
B. 301
C. 301.56
D. 301.56560000
Output:
A
32. Find output
An expression involving byte, short, int, and
literal numbers is promoted to which of these?
A. int
B. byte
C. long
D. float
Output
A
33. Find output
Which of these coding types is used for data
type characters in Java?
A. ASCII
B. ISO-LATIN-1
C. UNICODE
D. None of the mentioned
Output
C
34. Find output
Which one is a valid declaration of a boolean?
A. boolean b1 = 1;
B. boolean b2 = ‘false’;
C. boolean b3 = false;
D. boolean b4 = ‘true’
Output
C
35. Find output
Default value of character data type in Java
Programming is
A) Undefine
B) null
C) 0
D) ‘\u0000’
Output
D
36. Find output
Default value of String in Java Programming is
a) 0
b) null
c) False
d) “”
Output
B
37. Find output
Compiler never assigns a default value to an
uninitialized local variable in Java Programming
a) False
b) True
Output
B
38. Find output
Which of the following data type is not
considered as data type in Java Programming.
a) String
b) int
c) char
d) boolean
output
a
39. Find Output
System.out.println('j' + 'a' + 'v' + 'a');
Output
418
40. Find output
int $_ = 5;
Output
Choices:
a) Nothing
b) Error
Answer: a) Nothing
Reason: It looks like $ will cause an error, but it
won’t. In java, identifier rule says, identifier can
start with any alphabet or underscore (“_”) or
dollar (“$”). So answer is Nothing.