Java Multiple Choice Questions & Answers on Java.lang – Object & Math Class for Freshers

https://www.computersprofessor.com/2017/12/java-multiple-choice-questions-answers_15.html
1. Which of these class is superclass of all other classes?
a) Math
b) Process
c) System
d) Object
Answer: d
Explanation: The object class class is 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) dublicate()
d) dito()
Answer: a
3. What is the value of double constant ‘E’ defined in Math class?
a) approximately 3
b) approximately 3.14
c) approximately 2.72
d) approximately 0
Answer: c
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, trignometry, as well as several general purpose methods. Example : sin(), cos(), exp(), sqrt() etc.
6. Which of these class encapsulate the run time state of an object or an interface?
a) Class
b) Object
c) Runtime
d) System
Answer: a
7. What is the value of “d” after this line of code has been executed?
double d = Math.round ( 2.5 + Math.random() );
a) 2
b) 3
c) 4
d) 2.5
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 is the output of this 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
b) 3
c) 3.0
d) 3.1
Answer: b
9. What is the output of this 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) flase
c) 3.1
d) 4.5
b) flase
c) 3.1
d) 4.5
Answer: d
10. What is the output of this 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
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.