Programming  Java  Variables

Answer each question, once completed click submit.

1. Which of the following is correct statement?

Boolean true value is 1 and false value is 0 Every private class has a wrapper class Constant identifier precede with a reserved word final System.out.println() method also flushes the buffer

Workspace

Discuss

2. Size of an integer can be

3 bytes 4 bytes 5 bytes 6 bytes

Workspace

Discuss

3. For which of the following data types the ValueOf() method is NOT overloaded in the string class?

Float Boolean Object None of these

Workspace

Discuss

4. Integer is a

Adapter class Inner class Not a class Wrapper class

Workspace

Discuss

5. Which of the following variable declaration would not compile in Java program?

int VAR; int var1; int 1_var; All are correct

Workspace

Discuss

6. Among these expressions, which is(are) of type String?

"0" 0 a. and b. None of these

Workspace

Discuss

7. Which of the following line will not compile assuming b1, b2 and b3 are byte variables and J is Int variable?

b1 = 3; b3 = b1 * b2; b3 = 10 * b1; b2 = (byte) j;

Workspace

Discuss

8. Which are the valid declarations for an integer literal? (i) 0 (ii) -5 (iii) 0416 (iv) 0xabcdef

(i) and (ii) (i), (ii) and (iii) (iv) All of these

Workspace

Discuss

9. Which one does not have a valueOf(String) method?

Integer Boolean Long Short

Workspace

Discuss

10. Which of the following is NOT an example of a data type?

int public boolean double

Workspace

Discuss

11. Int, long, byte, short are the data types of _____data types?

unsigned signed both a. and b. None of these

Workspace

Discuss

12. Which of the following is correct?

int a = 16, a>>2 = 4 int b = -8, b>>1 = -4 int a = 16, a>>>2 = 4 All of the above

Workspace

Discuss

13. Which of the following is the mutable wrapper class?

Integer BigInteger Boolean Character

Workspace

Discuss

14. What is the range of data type short in Java?

-128 to 127 -32768 to 32767 -2147483648 to 2147483647 None of the mentioned

Workspace

Discuss

15. What is the range of data type byte in Java?

-128 to 127 -32768 to 32767 -2147483648 to 2147483647 None of the mentioned

Workspace

Discuss

16. 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;

1 and 2 2 and 3 3 and 4 All statements are correct.

Workspace

Discuss

17. An expression involving byte, int, and literal numbers is promoted to which of these?

int long byte float

Workspace

Discuss

18. 18. Which of these literals can be contained in a data type float variable?

1.7e-308 3.4e-038 1.7e+308 3.4e-050

Workspace

Discuss

19. Which data type value is returned by all transcendental math functions?

int float double long

Workspace

Discuss

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

16.34 16.566666644 16.46666666666667 16.46666666666666

Workspace

Discuss

21. What is the output of this program?
class conversion {
public static void main(String args[])
{
double a = 295.04;
int b = 300;
byte c = (byte) a;
byte d = (byte) b;
System.out.println(c + " " + d.;
}
}

38 43 39 44 295 300 295.04 300

Workspace

Discuss

22. What is the output of this program?
class increment {
public static void main(String args[])
{
int g = 3;
System.out.print(++g * 8);
}
}

25 24 32 33

Workspace

Discuss

23. What is the output of this 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);
}
}

301.5656 301 301.56 301.56560000

Workspace

Discuss

24. What is the numerical range of a char in Java?

-128 to 127 0 to 256 0 to 32767 0 to 65535

Workspace

Discuss

25. Which of these coding types is used for data type characters in Java?

ASCII ISO-LATIN-1 UNICODE None of the mentioned

Workspace

Discuss

26. Which of these values can a boolean variable contain?

True & False 0 & 1 Any integer value true

Workspace

Discuss

27. Which of these occupy first 0 to 127 in Unicode character set used for characters in Java?

ASCII ISO-LATIN-1 None of the mentioned ASCII and ISO-LATIN1

Workspace

Discuss

28. Which one is a valid declaration of a boolean?

boolean b1 = 1; boolean b2 = ‘false’; boolean b3 = false; boolean b4 = ‘true’

Workspace

Discuss

29. What is the output of this program?
class array_output {
public static void main(String args[])
{
char array_variable [] = new char[10];
for (int i = 0; i < 10; ++i) {
array_variable[i] = i;
System.out.print(array_variable[i] + "" );
i++;
}
}
}

i i i i i 0 1 2 3 4 i j k l m None of the mentioned

Workspace

Discuss

30. What is the output of this program?
class mainclass {
public static void main(String args[])
{
char a = A;
a++;
System.out.print((int)a);
}
}

66 67 65 64

Workspace

Discuss

31. What is the output of this 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);
}
}

0 1 true false

Workspace

Discuss

32. What is the output of this program?
class booloperators {
public static void main(String args[])
{
boolean var1 = true;
boolean var2 = false;
System.out.println((var2 & var2));
}
}

0 1 true false

Workspace

Discuss

33. What is the output of this program?
class asciicodes {
public static void main(String args[])
{
char var1 = A;
char var2 = a;
System.out.println((int)var1 + " " + (int)var2);
}
}

162 65 97 67 95 66 98

Workspace

Discuss

34. Which of these is data type long literal?

0x99fffL ABCDEFG 0x99fffa 99671246

Workspace

Discuss

35. Which of these can be returned by the operator & ?

Integer Boolean Character Integer or Boolean

Workspace

Discuss

36. Literals in java must be preceded by which of these?

L l D L and l

Workspace

Discuss

37. Literal can be of which of these data types?

integer float boolean all of the mentioned

Workspace

Discuss

38. Which of these can not be used for a variable name in Java?

identifier keyword identifier & keyword None of the mentioned

Workspace

Discuss

39. What is the output of this program?
class evaluate {
public static void main(String args[])
{
int a[] = {1,2,3,4,5};
int d[] = a;
int sum = 0;
for (int j = 0; j < 3; ++j)
sum += (a[j] * d[j + 1]) + (a[j + 1] * d[j]);
System.out.println(sum);
}
}

38 39 40 41

Workspace

Discuss

40. Which of these is incorrect string literal?

“Hello World” “Hello” “World” ab12

Workspace

Discuss
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25
26 27 28 29 30
31 32 33 34 35
36 37 38 39 40