Java - Java.lang Class Questions and Answers

Take Exam

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
Show Answer Report

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);
Show Answer Report

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
Show Answer Report

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
Show Answer Report

5. Which of the following is the root class for all Java classes?

  • Object
  • Class
  • Main
  • Root
Show Answer Report

6. What method is used to get the string representation of an object?

  • toString()
  • getString()
  • stringValue()
  • convertString()
Show Answer Report

7. Which method is called when an object is created?

  • Constructor
  • init()
  • start()
  • new()
Show Answer Report

8. What is the return type of the hashCode() method?

  • int
  • String
  • Object
  • boolean
Show Answer Report

9. Which class provides the System.out.println() method?

  • System
  • PrintStream
  • Object
  • String
Show Answer Report

10. What is the purpose of the finalize() method?

  • Cleanup before garbage collection
  • Initialize object
  • Compare objects
  • Create object copy
Show Answer Report
Questions and Answers for Competitive Exams Various Entrance Test