Java - Java.lang Class Questions and Answers
The Java.lang Class questions with answers topic is a key area in Java programming questions and answers asked in major technical exams and placement tests. The java.lang package forms the foundation of Java, offering essential classes like Object, String, and Math. Understanding these concepts is vital for cracking programming interview questions at companies like TCS, Infosys, and Accenture. In this section, we’ll explore frequently asked questions about java.lang classes, constructors, and methods with detailed explanations to help you master core Java fundamentals and boost your placement preparation.
Java - Java.lang Class
Showing 10 of
24 questions
1. What is the value of "d" after this line of code has been executed? double d = Math.round ( 2.5 + Math.random( ));
- 2
- 3
- 4
- 2.5
2. Which of the following would compile without error?
- int a = Math.abs(-5);
- int b = Math.abs(5.0);
- int c = Math.abs(5.5F);
- int d = Math.abs(5L);
3. Which of the following are valid calls to Math.max? Math.max(1,4) Math.max(2.3, 5) Math.max(1, 3, 5, 7) Math.max(-1.5, -2.8f)
- 1, 2 and 4
- 2, 3 and 4
- 1, 2 and 3
- 2, 3 and 4
4. public class Myfile { public static void main (String[] args) { String biz = args[1]; String baz = args[2]; String rip = args[3]; System.out.println("Arg is " + rip); } } Select how you would start the program to cause it to print: Arg is 2
- java Myfile 222
- java Myfile 1 2 2 3 4
- java Myfile 1 3 2 2
- java Myfile 0 1 2 3
5. Which of the following is the root class for all Java classes?
- Object
- Class
- Main
- Root
6. What method is used to get the string representation of an object?
- toString()
- getString()
- stringValue()
- convertString()
7. Which method is called when an object is created?
- Constructor
- init()
- start()
- new()
9. Which class provides the System.out.println() method?
- System
- PrintStream
- Object
- String
10. What is the purpose of the finalize() method?
- Cleanup before garbage collection
- Initialize object
- Compare objects
- Create object copy