Sail E0 Webinar

MCQs

Total Questions : 50 | Page 3 of 5 pages
Question 21.


What is the output of this program?


class Output {
public static void main(String args[]) {
Double i = new Double(257.5);
boolean x = i.isNaN();
System.out.print(x);
}
}
  1.    true
  2.    false
  3.    0
  4.    1
 Discuss Question
Answer: Option B. -> false

i.isNaN() method returns returns true if i is not a number and false when i is a number. 

Here false is returned because i is a number i:e 257.5.
Output:
$ javac Output.java
$ java Output
false


Question 22.

Which of these methods is used to obtain value of invoking object as a long?


  1.    long value()
  2.    long longValue()
  3.    Long longvalue()
  4.    Long Longvalue()
 Discuss Question
Answer: Option B. -> long longValue()

long longValue() is used to obtain value of invoking object as a long.


Question 23.


What is the output of this program?


class Output {
public static void main(String args[]) {
String str = "true";
boolean x = Boolean.valueOf(str);
System.out.print(x);
}
}
  1.    true
  2.    flase
  3.    Compilation Error
  4.    Runtime Error
 Discuss Question
Answer: Option A. -> true

valueOf() returns true if the specified string contains "true" in lower or uppercase 

and false otherwise.
Output:
$ javac Output.java
$ java Output
true



Question 24.


What is the output of this program?


class Output {
public static void main(String args[]) {
int a = Character.MAX_VALUE;
System.out.print((char)a);
}
}
 Discuss Question
Answer: Option A. -> true

Character.MAX_VALUE returns the largest character value, which is of character '?'.
Output:
$ javac Output.java
$ java Output
?

Question 25.


What is the output of this program?


class Output {
public static void main(String args[]) {
Double i = new Double(257.5);
Double x = i.MAX_VALUE;
System.out.print(x);
}
}
  1.    0
  2.    1.7976931348623157E308
  3.    1.7976931348623157E30
  4.    None of the mentioned
 Discuss Question
Answer: Option B. -> 1.7976931348623157E308

The super class of Double class defines a constant MAX_VALUE above which a 

number is considered to be infinity. MAX_VALUE is 1.7976931348623157E308.
Output:
$ javac Output.java
$ java Output
1.7976931348623157E308


Question 26.

Which of the following is method of wrapper Integer for converting the value of 

an object into byte?


  1.    bytevalue()
  2.    byte bytevalue()
  3.    Bytevalue()
  4.    Byte Bytevalue().
 Discuss Question
Answer: Option B. -> byte bytevalue()

None.


Question 27.

Which of these coding techniques is used by method isDefined()?


  1.    Latin
  2.    ASCII
  3.    ANSI
  4.    UNICODE
 Discuss Question
Answer: Option D. -> UNICODE

isDefined() returns true if ch is defined by Unicode. Otherwise, it returns false.


Question 28.

Which of these class have only one field?


  1.    Character
  2.    Boolean
  3.    Byte
  4.    void
 Discuss Question
Answer: Option D. -> void

Void class has only one field - TYPE, ehich holds a reference to the Class object 

for type void. We do not create instance of this class.


Question 29.

Which of these exceptions is thrown by compareTo() method defined in double

wrapper?


  1.    IOException
  2.    SystemException
  3.    CastException
  4.    ClassCastException
 Discuss Question
Answer: Option D. -> ClassCastException

compareTo() methods compare the specified object to be double, if it is not then 

ClassCastException is thrown.


Question 30.

Which of these exceptions is thrown by compareTo() method defined in double 

wrapper?


  1.    IOException
  2.    SystemException
  3.    CastException
  4.    ClassCastException
 Discuss Question
Answer: Option D. -> ClassCastException

compareTo() methods compare the specified object to be double, if it is not then 

ClassCastException is thrown.


Latest Videos

Latest Test Papers