Sail E0 Webinar

MCQs

Total Questions : 45 | Page 4 of 5 pages
Question 31.


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);
}
}
  1.    162
  2.    65 97
  3.    67 95
  4.    66 98
 Discuss Question
Answer: Option B. -> 65 97

ASCII code for ‘A’ is 65 and for ‘a’ is 97.
output:
$ javac asciicodes.java
$ java asciicodes
65 97


Question 32.


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);
}
}
  1.    16.34
  2.    16.566666644
  3.    16.46666666666667
  4.    16.46666666666666
 Discuss Question
Answer: Option C. -> 16.46666666666667

None.
output:
$ javac average.java
$ java average
16.46666666666667


Question 33.


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));
}
}
  1.    0
  2.    1
  3.    true
  4.    false
 Discuss Question
Answer: Option D. -> false

 boolean '&' operator always returns true or false. var1 is defined true and var2 is defined false hence their '&' operator result is false.
output:
$ javac booloperators.java
$ java booloperators
false


Question 34.


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);
}
}
  1.    0
  2.    1
  3.    true
  4.    false
 Discuss Question
Answer: Option C. -> true

None.
output:
$ javac mainclass.java
$ java mainclass
true


Question 35.

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


  1.    1.7e-308
  2.    3.4e-038
  3.    1.7e+308
  4.    3.4e-050
 Discuss Question
Answer: Option B. -> 3.4e-038

Range of data type float is 3.4e-038 to 3.4e+308.


Question 36.


What is the output of this program?


class mainclass {
public static void main(String args[])
{
char a = 'A';
a++;
System.out.print((int)a);
}
}
  1.    66
  2.    67
  3.    65
  4.    64
 Discuss Question
Answer: Option A. -> 66

ASCII value of 'A' is 65, on using ++ operator character value increments by one.
output:
$ javac mainclass.java
$ java mainclass
66



Question 37.

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


  1.    int
  2.    float
  3.    double
  4.    long
 Discuss Question
Answer: Option C. -> double

None.


Question 38.

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


  1.    int
  2.    long
  3.    byte
  4.    float
 Discuss Question
Answer: Option A. -> int

An expression involving bytes, ints, shorts, literal numbers, the entire expression is promoted 

to int before any calculation is done.


Question 39.

What is the range of data type byte in Java?


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

Byte occupies 8 bits in memory. Its range is from -128 to 127.


Question 40.

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


  1.    ASCII
  2.    ISO-LATIN-1
  3.    None of the mentioned
  4.    ASCII and ISO-LATIN1
 Discuss Question
Answer: Option D. -> ASCII and ISO-LATIN1

First 0 to 127 character set in Unicode are same as those of ISO-LAIN-1 and ASCII.


Latest Videos

Latest Test Papers