Java Programming Multiple Choice Questions - Java Lang
This section focuses on the "Java Lang" of the Java programming. These Multiple Choice Questions (mcq) should be practiced to improve the Java programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.
1.Which of the following would compile without error?
Explanation: The return value of the Math.abs() method is always the same as the type of the parameter passed into that method.
In the case of A, an integer is passed in and so the result is also an integer which is fine for assignment to "int a".
The values used in B, C & D respectively are a double, a float and a long. The compiler will complain about a possible loss of precision if we try to assign the results to an "int".
2. Which of these classes encapsulate runtime state of an object?
Explanation: Class encapsulate runtime state of an object.
3. Which of these classes is not included in java.lang?
Explanation:Array class is a member of java.util..
4. Which of the following will produce an answer that is closest in value to a double, d, while not being greater than d?
Explanation:The casting to an int is a smokescreen.
5. Which of these methods returns the class of an object?
Explanation: getClass() methods returns the class of an object.
6.Which of these class have only one field ‘TYPE’?
Explanation: The Void class has one field, TYPE, which holds a reference to the Class object for the type void.
7. Which of the following method of Process class can terminate a process?
Explanation: Kills the subprocess. The subprocess represented by this Process object is forcibly terminated
8. Standard output variable ‘out’ is defined in which class?
Explanation: Standard output variable ‘out’ is defined in System class. out is usually used in print statement i:e System.out.print().
9. Which of these class can encapsulate an entire executing program?
10. Which of the following is method of System class is used to find how long a program takes to execute?
Also check :