Quiz About Java Data Types
Quiz About Java Data Types
garbage value
compiler error
runtime error
Discuss it
Question 1 ‒ Explanation
Unlike class members, local variables of methods must be assigne
d a value to before they are accessed, or it is a compile error.
Question 2
class Test {
public static void main(String[] args) {
for(int i = 0; 0; i++)
{
System.out.println("Hello");
break;
}
}
}
Hello
Empty Output
Compiler error
Runtime error
Discuss it
Question 2 ‒ Explanation
The error is in for loop where 0 is used in place of boolean value.
Unlike C++, use of non boolean variables in place of bool is not all
owed
Question 3
Java
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 );
}
}
8.8
8.800000095367432
Discuss it
Question 3 ‒ Explanation
Arithmetic conversions are implicitly performed to cast the values
to a common type. The compiler first performs integer promotion.
If the operands still have different types, then they are converted t
o the type that appears highest in the hierarchy.
Question 4
Discuss it
Question 4 ‒ Explanation
In JAVA, constant are not declared using \'static\' keyword and a cl
ass can implement multiple interfaces but class can inherit one cla
ss only. So, option (B) is correct.