Mcq On Java Data types

11. What will be the output of the program?
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

View Answer


12. What will be the output of the program?
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

View Answer


13.What will be the output of the program?
class mainclass {
public static void main(String args[])
{
boolean var1 = true;
boolean var2 = false;
if (var1)
System.out.println(var1);
else
System.out.println(var2);
}
}

A. 0
B. 1
C. true
D. false

View Answer


14. Predict the output of the following program.
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. 8.0

View Answer


15. Which of the following are legal lines of Java code?
1. int w = (int)888.8;
2. byte x = (byte)100L;
3. long y = (byte)100;
4. byte z = (byte)100L;

A. 1 and 2
B. 2 and 3
C. 3 and 4
D. All statements are correct

View Answer


16. What is the output of this program?
class average { public static void main(String args[])
{
double num[] = {5.5, 10.1, 11, 12.8, 56.9, 2.5};
double result;
result = 0;
for (int i = 0; i < 6; ++i)
result = result + num[i];
System.out.print(result/6);
}
}

A. 16.34
B. 16.566666644
C. 16.46666666666667
D. 16.46666666666666

View Answer


17. What is the output of this program?
class output {
public static void main(String args[])
{
double a, b,c;
a = 4.0/0;
b = 0/3.0;
c=0/0.0;
System.out.println(a);
System.out.println(b);
System.out.println(c);
}
}


A. Infinity
B. 0.0
C. NaN
D. all of the mentioned

View Answer


18. What will be the output of the program?
class increment {
public static void main(String args[])
{
int g = 4;
System.out.print(++g * 8);
}
}

A. 32
B. 36
C. 40
D. 48

View Answer


19. What will be the output of the program?

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);
}
}

A. 301.5656
B. 301
C. 301.56
D. 301.56560000

View Answer


20. What will be the output of the program?
class increment {
public static void main(String args[])
{
int g = 6;
System.out.print(--g * 8);
}
}

A. 48
B. 40
C. 56
D. 44

View Answer






Also check :


Discussion


* You must be logged in to add comment.