Sail E0 Webinar

MCQs

Total Questions : 50 | Page 1 of 5 pages
Question 1.


What is the output of this program?


class Output {
public static void main(String args[]) {
Long i = new Long(256);
System.out.print(i.hashCode());
}
}
  1.    256
  2.    256.0
  3.    256.00
  4.    257.00
 Discuss Question
Answer: Option A. -> 256

None.
Output:
$ javac Output.java
$ java Output
256


Question 2.


What is the output of this program?


class Output {
public static void main(String args[]) {
Double y = new Double(257.57812);
Double i = new Double(257.578123456789);
try {
int x = i.compareTo(y);
System.out.print(x);
}
catch(ClassCastException e) {
System.out.print("Exception");
}
}
}
  1.    0
  2.    1
  3.    Exception
  4.    None of the mentioned
 Discuss Question
Answer: Option B. -> 1

i.compareTo() methods two double values, if they are equal then 0 is returned and if 

not equal then 1 is returned, here 257.57812 and 257.578123456789 are not equal 

henc 1 is returned and stored in x.
Output:
$ javac Output.java
$ java Output
1


Question 3.


What is the output of this program?


class Output {
public static void main(String args[]) {
Double y = new Double(257.57812);
Double i = new Double(257.578123456789);
try {
int x = i.compareTo(y);
System.out.print(x);
}
catch(ClassCastException e) {
System.out.print("Exception");
}
}
}
  1.    0
  2.    1
  3.    Exception
  4.    None of the mentioned
 Discuss Question
Answer: Option B. -> 1

i.compareTo() methods two double values, if they are equal then 0 is returned and if 

not equal then 1 is returned, here 257.57812 and 257.578123456789 are not equal 

hence 1 is returned and stored in x.
Output:
$ javac Output.java
$ java Output
1


Question 4.


What is the output of this program?


class Output {
public static void main(String args[]) {
char a = '@';
boolean x = Character.isLetter(a);
System.out.print(x);
}
}
  1.    b
  2.    c
  3.    B
  4.    C
 Discuss Question
Answer: Option C. -> B

None.
Output:
$ javac Output.java
$ java Output
B

Question 5.


What is the output of this program?


class Output {
public static void main(String args[]) {
String x = Boolean.toString(false);
}
}
  1.    true
  2.    false
  3.    System Dependent
  4.    Compilation Error
 Discuss Question
Answer: Option B. -> false

toString() Returns a String object representing the specified boolean. If the specified 

boolean is true, then the string "true" will be returned, otherwise the string "false" will 

be returned
Output:
$ javac Output.java
$ java Output
false


Question 6.


What is the output of this program?


class Output {
public static void main(String args[]) {
Integer i = new Integer(257);
float x = i.floatValue();
System.out.print(x);
}
}
  1.    0
  2.    1
  3.    257
  4.    257.0
 Discuss Question
Answer: Option D. -> 257.0

None.
Output:
$ javac Output.java
$ java Output
257.0


Question 7.


What is the output of this program?


class Output {
public static void main(String args[]) {
char a = (char) 98;
a = Character.toUpperCase(a);
System.out.print(a);
}
}
  1.    b
  2.    c
  3.    B
  4.    C
 Discuss Question
Answer: Option C. -> B

None.
Output:
$ javac Output.java
$ java Output
B

Question 8.


What is the output of this program?


class Output {
public static void main(String args[]) {
Double i = new Double(257.578123456789);
float x = i.floatValue();
System.out.print(x);
}
}
  1.    0
  2.    257.0
  3.    257.57812
  4.    257.578123456789
 Discuss Question
Answer: Option C. -> 257.57812

floatValue() converts the value of wrapper i into float, since float can measure till 5 

places after decimal hence 257.57812 is stored in floating point variable x.
Output:
$ javac Output.java
$ java Output
257.57812


Question 9.


What is the output of this program?


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

parseBoolean() Parses the string argument as a boolean. The boolean returned 

Question 10.


What is the output of this program?


class Output {
public static void main(String args[]) {
Double i = new Double(257.578123456789);
float x = i.floatValue();
System.out.print(x);
}
}
  1.    0
  2.    257.0
  3.    257.57812
  4.    257.578123456789
 Discuss Question
Answer: Option C. -> 257.57812

floatValue() converts the value of wrapper i into float, since float can measure till 5 

places after decimal hence 257.57812 is stored in floating point variable x.
Output:
$ javac Output.java
$ java Output
257.57812


Latest Videos

Latest Test Papers