Java Questions and Answers Part-22

1. Which of these class is a superclass of all other classes?
a) Math
b) Process
c) System
d) Object

Answer: d
Explanation: The object class class is a superclass of all other classes.

2. Which of these method of Object class can generate duplicate copy of the object on which it is called?
a) clone()
b) copy()
c) duplicate()
d) dito()

Answer: a
Explanation: clone()

3. What is the value of double consonant ‘E’ defined in Math class?
a) approximately 3
b) approximately 3.14
c) approximately 2.72
d) approximately 0

Answer: c
Explanation: approximately 2.72

4. Which of these method is a rounding function of Math class?
a) max()
b) min()
c) abs()
d) all of the mentioned

Answer: d
Explanation: max(), min() and abs() are all rounding functions.

5. Which of these class contains only floating point functions?
a) Math
b) Process
c) System
d) Object

Answer: a
Explanation: Math class contains all the floating point functions that are used for geometry, trigonometry, as well as several general purpose methods. Example : sin(), cos(), exp(), sqrt() etc.

6. Which of these class encapsulate the runtime state of an object or an interface?
a) Class
b) Object
c) Runtime
d) System

Answer: a
Explanation: Class

7. What is the value of “d” in the following Java code snippet?
double d = Math.round ( 2.5 + Math.random() );
a) 2
b) 3
c) 4
d) 2.5

Answer: b
Explanation: The Math.random() method returns a number greater than or equal to 0 and less than 1. so 2.5 will be greater than or equal to 2.5 and less than 3.5, we can be sure that Math.round() will round that number to 3.

8. What will be the output of the following Java program?
class Output
{
public static void main(String args[])
{
int x = 3.14;
int y = (int) Math.abs(x);
System.out.print(y);
}
}
a) 0
b) 3
c) 3.0
d) 3.1

Answer: b
Explanation:
Output:
3

9. What will be the output of the following Java program?
class Output
{
public static void main(String args[])
{
double x = 3.1;
double y = 4.5;
double z = Math.max( x, y );
System.out.print(z);
}
}
a) true
b) false
c) 3.1
d) 4.5

Answer: d
Explanation:
Output:
4.5

10. What will be the output of the following Java program?
class Output
{
public static void main(String args[])
{
double x = 2.0;
double y = 3.0;
double z = Math.pow( x, y );
System.out.print(z);
}
}
a) 2.0
b) 4.0
c) 8.0
d) 9.0

Answer: c
Explanation: Math.pow(x, y) methods returns value of y to the power x, i:e x ^ y, 2.0 ^ 3.0 = 8.0.
Output:
8.0