Sail E0 Webinar

MCQs

Total Questions : 45 | Page 5 of 5 pages
Question 41.


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++;
}
}
}
  1.    i i i i i
  2.    0 1 2 3 4
  3.    i j k l m
  4.    None of the mentioned
 Discuss Question
Answer: Option A. -> i i i i i

None.
output:
$ javac array_output.java
$ java array_output
i i i i i


Question 42.

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.    1 and 2
  2.    2 and 3
  3.    3 and 4
  4.    All statements are correct.
 Discuss Question
Answer: Option D. -> All statements are correct.

Statements (1), (2), (3), and (4) are correct. (1) is correct because when a floating-point 

number (a double in this case) is cast to an int, it simply loses the digits after the decimal.

(2) and (4) are correct because a long can be cast into a byte. If the long is over 127, it 

loses its most significant (leftmost) bits.(3) actually works, even though a cast is not 

necessary, because a long can store a byte.


Question 43.

Which of these values can a boolean variable contain?


  1.    True & False
  2.    0 & 1
  3.    Any integer value
  4.    true
 Discuss Question
Answer: Option A. -> True & False

Boolean variable can contain only one of two possible values, true and false.


Question 44.

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


  1.    ASCII
  2.    ISO-LATIN-1
  3.    UNICODE
  4.    None of the mentioned
 Discuss Question
Answer: Option C. -> UNICODE

Unicode defines fully international character set that can represent all the characters found 

in all human languages. Its range is from 0 to 65536.



Question 45.

What is the range of data type short in Java?


  1.    -128 to 127
  2.    -32768 to 32767
  3.    -2147483648 to 2147483647
  4.    None of the mentioned
 Discuss Question
Answer: Option B. -> -32768 to 32767

Short occupies 16 bits in memory. Its range is from -32768 to 32767.


Latest Videos

Latest Test Papers