Sail E0 Webinar

MCQs

Total Questions : 50 | Page 2 of 5 pages
Question 11.


What is the output of this program?


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

 i.byteValue() method returns the value of wrapper i as a byte value. i is 257, range of byte is 

256 therefore i value exceeds byte range by 1 hence 1 is returned and stored in x.
Output:
$ javac Output.java
$ java Output
1


Question 12.


What is the output of this program?


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

i.intValue() method returns the value of wrapper i as a Integer. i is 257.578 is double 

number when converted to an integer data type its value is 257.
Output:
$ javac Output.java
$ java Output
257


Question 13.


What is the output of this program?


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

i.byteValue() method returns the value of wrapper i as a byte value. i is 257, range 

Question 14.


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 a Boolean  instance representing the  specified  boolean value. If 

Question 15.


What is the output of this program?


class Output {
public static void main(String args[]) {
char a[] = {'a', '5', 'A', ' '};
System.out.print(Character.isDigit(a[0])+ " ");
System.out.print(Character.isWhitespace(a[3])+ " ");
System.out.print(Character.isUpperCase(a[2]));
}
}
  1.    true false true
  2.    false true true
  3.    true true false
  4.    false false false
 Discuss Question
Answer: Option B. -> false true true

Character.isDigit(a[0]) checks for a[0], whether it is  a  digit or  not, since a[0] i:e 'a' is 

a character false is returned. a[3] is a whitespace hence Character.isWhitespace(a[3]) 

returns a true. a[2] is an upper case letter i:e 'A' hence Character.isUpperCase(a[2]) 

returns true.
Output:
$ javac Output.java
$ java Output
false true true



Question 16.


What is the output of this program?


class Output {
public static void main(String args[]) {
char a[] = {'a', '5', 'A', ' '};
System.out.print(Character.isDigit(a[0]) + " ");
System.out.print(Character.isWhitespace(a[3]) + " ");
System.out.print(Character.isUpperCase(a[2]));
}
}
  1.    true false true
  2.    false true true
  3.    true true false
  4.    false false false
 Discuss Question
Answer: Option B. -> false true true

Character.isDigit(a[0]) checks for a[0], whether it is a digit or not, since a[0] i:e ‘a’ is a character 

false is returned. a[3] is a whitespace hence Character.isWhitespace(a[3]) returns a true. a[2] is

an upper case letter i:e ‘A’ hence Character.isUpperCase(a[2]) returns true.
Output:
$ javac Output.java
$ java Output
false true true


Question 17.


What is the output of this program?


class Output {
public static void main(String args[]) {
String str = "true false 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
false


Question 18.


What is the output of this program?


class Output {
public static void main(String args[]) {
int a = Character.MIN_VALUE;
System.out.print((char)a);
}
}
  1.    
  2.    !
  3.    @
  4.    Space
 Discuss Question
Answer: Option D. -> Space

Character.MIN_VALUE returns the smallest character value, which is of space character ' '

Output: 

$ javac Output.java 

$ java Output


Question 19.


What is the output of this program?


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

i.byteValue() method returns the value of wrapper i as a byte value. i is 257, range 

of byte is 256 therefore i value exceeds byte range by 1 hence 1 is returned and 

stored in x.

Output:
$ javac Output.java
$ java Output
1


Question 20.


What is the output of this program?


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

The super class of Byte class defines a constant MIN_VALUE below which a number 

Latest Videos

Latest Test Papers