A directory of Objective Type Questions covering all the Computer Science subjects. Here you can access and discuss Multiple choice questions and answers for various compitative exams and interviews.

211. What will be the output of the program?

try 
{
    Float f1 = new Float("3.0");
    int x = f1.intValue();
    byte b = f1.byteValue();
    double d = f1.doubleValue();
    System.out.println(x + b + d);
}
catch (NumberFormatException e) /* Line 9 */
{
    System.out.println("bad number"); /* Line 11 */
}
a. 9.0
b. bad number
c. Compilation fails on line 9.
d. Compilation fails on line 11.
View Answer Report Discuss Too Difficult!
Answer: (a).9.0

212. What will be the output of the program?

class Q207 
{ 
    public static void main(String[] args) 
    {
        int i1 = 5; 
        int i2 = 6; 
        String s1 = "7"; 
        System.out.println(i1 + i2 + s1); /* Line 8 */
    } 
}
a. 18
b. 117
c. 567
d. Compiler error
View Answer Report Discuss Too Difficult!
Answer: (b).117

213. What will be the output of the program?

public class SqrtExample 
{
    public static void main(String [] args) 
    {
        double value = -9.0;
        System.out.println( Math.sqrt(value));
    }
}
a. 3.0
b. -3.0
c. NaN
d. Compilation fails.
View Answer Report Discuss Too Difficult!
Answer: (c).NaN

214. What will be the output of the program?

String s = "ABC"; 
s.toLowerCase(); 
s += "def"; 
System.out.println(s);
a. ABC
b. abc
c. ABCdef
d. Compile Error
View Answer Report Discuss Too Difficult!
Answer: (c).ABCdef

215. Which statement is true given the following?

Double d = Math.random();
a. 0.0 < d <= 1.0
b. 0.0 <= d < 1.0
c. Compilation fail
d. Cannot say.
View Answer Report Discuss Too Difficult!
Answer: (b).0.0 <= d < 1.0

216. Which two statements are true about wrapper or String classes?

1. If x and y refer to instances of different wrapper classes, then the fragment x.equals(y) will cause a compiler failure.
2. If x and y refer to instances of different wrapper classes, then x == y can sometimes be true.
3. If x and y are String references and if x.equals(y) is true, then x == y is true.
4. If x, y, and z refer to instances of wrapper classes and x.equals(y) is true, and y.equals(z) is true, then z.equals(x) will always be true.
5. If x and y are String references and x == y is true, then y.equals(x) will be true.
a. 1 and 2
b. 2 and 3
c. 3 and 4
d. 4 and 5
View Answer Report Discuss Too Difficult!
Answer: (d).4 and 5

217. Which of the following will produce an answer that is closest in value to a double, d, while not being greater than d?
a. (int)Math.min(d);
b. (int)Math.max(d);
c. (int)Math.abs(d);
d. (int)Math.floor(d);
View Answer Report Discuss Too Difficult!
Answer: (d).(int)Math.floor(d);

218. What two statements are true about the result obtained from calling Math.random()?


1. The result is less than 0.0.
2. The result is greater than or equal to 0.0..
3. The result is less than 1.0.
4. The result is greater than 1.0.
5. The result is greater than or equal to 1.0.
a. 1 and 2
b. 2 and 3
c. 3 and 4
d. 4 and 5
View Answer Report Discuss Too Difficult!
Answer: (b).2 and 3