Java MCQs on Object & Math classes of Java Programming Language.
1. Which of these class is a superclass of all other classes? Answer: d 2. Which of these method of Object class can generate duplicate copy of the object on which it is called? Answer: a 3. What is the value of double consonant ‘E’ defined in Math class? Answer: c 4. Which of these method is a rounding function of Math class? Answer: d 5. Which of these class contains only floating point functions? Answer: a 6. Which of these class encapsulate the runtime state of an object or an interface? Answer: a 7. What is the value of “d” in the following Java code snippet? a) 2 Answer: b 8. What will be the output of the following Java program? a) 0 9. What will be the output of the following Java program? a) true 10. What will be the output of the following Java program? a) 2.0
a) Math
b) Process
c) System
d) Object
Clarification: The object class class is a superclass of all other classes.
a) clone()
b) copy()
c) duplicate()
d) dito()
Clarification: None.
a) approximately 3
b) approximately 3.14
c) approximately 2.72
d) approximately 0
Clarification: None.
a) max()
b) min()
c) abs()
d) all of the mentioned
Clarification: max(), min() and abs() are all rounding functions.
a) Math
b) Process
c) System
d) Object
Clarification: 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.
a) Class
b) Object
c) Runtime
d) System
Clarification: None. double d = Math.round ( 2.5 + Math.random() );
b) 3
c) 4
d) 2.5
Clarification: 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.
class Output
{
public static void main(String args[])
{
int x = 3.14;
int y = (int) Math.abs(x);
System.out.print(y);
}
}
b) 3
c) 3.0
d) 3.1
Clarification: None.
Output:
$ javac Output.java
$ java Output
3
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);
}
}
b) flase
c) 3.1
d) 4.5
Clarification: None.
Output:
$ javac Output.java
$ java Output
4.5
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);
}
}
b) 4.0
c) 8.0
d) 9.0
Clarification: Math.pow(x, y) methods returns value of y to the power x, i:e x ^ y, 2.0 ^ 3.0 = 8.0.
Output:
$ javac Output.java
$ java Output
8.0
