Java Questions & Answers – Java.lang – Object & Math Class

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

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()
View Answer

Answer: a
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

Answer: c
Explanation: None.
advertisement
advertisement

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

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
View Answer

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.
Note: Join free Sanfoundry classes at Telegram or Youtube

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

Answer: a
Explanation: None.

7. What is the value of “d” in the following Java code snippet?

advertisement
   double d = Math.round ( 2.5 + Math.random() );

a) 2
b) 3
c) 4
d) 2.5
View Answer

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.
advertisement

8. What will be the output of the following Java program?

  1.     class Output 
  2.     {
  3.          public static void main(String args[]) 
  4.          {
  5.              int x = 3.14;  
  6.              int y = (int) Math.abs(x);
  7.              System.out.print(y);
  8.          }
  9.     }

a) 0
b) 3
c) 3.0
d) 3.1
View Answer

Answer: b
Explanation: None.
Output:

$ javac Output.java
$ java Output
3

9. What will be the output of the following Java program?

  1.     class Output 
  2.     {
  3.          public static void main(String args[]) 
  4.         {
  5.             double x = 3.1;  
  6.             double y = 4.5;
  7.             double z = Math.max( x, y );
  8.             System.out.print(z);
  9.         }
  10.     }

a) true
b) flase
c) 3.1
d) 4.5
View Answer

Answer: d
Explanation: None.
Output:

$ javac Output.java
$ java Output
4.5

10. What will be the output of the following Java program?

  1.     class Output 
  2.     {
  3.          public static void main(String args[]) 
  4.         {
  5.             double x = 2.0;  
  6.             double y = 3.0;
  7.             double z = Math.pow( x, y );
  8.             System.out.print(z);
  9.         }
  10.     }

a) 2.0
b) 4.0
c) 8.0
d) 9.0
View Answer

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:

$ javac Output.java
$ java Output
8.0

Sanfoundry Global Education & Learning Series – Java Programming Language.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.