This section of our 1000+ Java MCQs focuses on Object & Math classes of Java Programming Language.
1. Which of these class is a superclass of all other classes?
a) Math
b) Process
c) System
d) Object
View Answer
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()
View Answer
Explanation: None.
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
View Answer
Explanation: None.
4. Which of these method is a rounding function of Math class?
a) max()
b) min()
c) abs()
d) all of the mentioned
View Answer
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
View Answer
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
View Answer
Explanation: None.
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
View Answer
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
View Answer
Explanation: None.
Output:
$ javac Output.java $ java 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) flase
c) 3.1
d) 4.5
View Answer
Explanation: None.
Output:
$ javac Output.java $ java 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
View Answer
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:
$ javac Output.java $ java Output 8.0
Sanfoundry Global Education & Learning Series – Java Programming Language.
- Apply for Computer Science Internship
- Check Programming Books
- Practice BCA MCQs
- Apply for Java Internship
- Practice Programming MCQs