Java is an adaptable language, letting developers to build programmes that would run on any system, independent of architecture or platform. According to the Java home page, Java is used by over 1 billion PCs and 3 billion mobile phones globally. Top Tech companies including Amazon, Twitter uses Java in its back- end. Getting a good grasp of top Java Placement MCQ Questions will surely provide you an edge in cracking such top companies.
Mobiprep handbooks are free downloadable placement preparation resources that can help you ace any company placement process. We have curated a list of the 40 most important Java MCQ questions with detailed explanations to ensure the best placement preparation.
These top Java Placement questions have been segmented into three sections:
Basic Java Placement Questions
Intermediate Java Placement Questions
Q 16. What is the output of a Bitwise AND (&) operation if one of the inputs/operands is 0?
0
1
0 or 1
None of the above
Correct Answer & Explanation: a
Because (0 & anything) is always equal to 0.
Q 17. What is the maximum number of ELSE-IF statements that can present in between starting IF and ending ELSE statements?
32
64
128
None of the above
Correct Answer & Explanation: d
We can write any number of ELSE-IF statements in a Java program.
Q 18. What does AWT stand for?
All Window Tools
All Writing Tools
Abstract Window Toolkit
Abstract Writing Toolkit
Correct Answer & Explanation: c
AWT stands for Abstract Window Toolkit, it is used by applets to interact with the user.
Q 19. Which one creates an instance of an array?
int[ ] ia = new int[15];
char[ ] ca = "Some String";
float fa = new float[20];
int ia[ ] [ ] = { 4, 5, 6 }, { 1,2,3 };
Correct Answer & Explanation: a
It uses correct array declaration and correct array construction, while others generate a compile error.
Q 20. switch(x) { default: System.out.println("Hello"); } Which two are acceptable types for x? (i) byte (ii) long (iii) char (iv) float
i & iii
ii & iv
i & iv
ii & iii
Correct Answer & Explanation: a
Switch statements are based on integer expressions and since both bytes and chars can implicitly be widened to an integer, these can also be used. Short is wrapper class and reference types can not be used as variables.
Q 21. What is the numerical range of char?
0 to 32767
0 to 65535
-256 to 255
-32768 to 32767
Correct Answer & Explanation: b
The char type is integral but unsigned. The range of a variable of type char is from 0 to 65535. Java characters are Unicode, which is a 16-bit encoding capable of representing a wide range of international characters.
Q 22. Which of these method of ArrayList class is used to obtain present size of an object?
size()
length()
index()
capacity()
Correct Answer & Explanation: a
Q 23. How can we remove an object from ArrayList?
remove() method
using iterator
remove () method and using iterator
delete() method
Correct Answer & Explanation: c
There are two ways to remove an object from ArrayList. We can use overloaded method remove(int index) or remove(Object obj). We can also use as an iterator to remove the object.
Q 24. Which of the following keywords is used for throwing exception manually?
finally
try
throw
catch
Correct Answer & Explanation: c
”throw” keyword is used for throwing exception manually in java program. User defined exceptions can be thrown too.
Q 25. Which component is responsible to optimize bytecode to machine code?
JVM
JDK
JIT
JRE
Correct Answer & Explanation: c
JIT optimizes bytecode to machine specific language code by compiling similar bytecodes at same time. This reduces overall time taken for compilation of bytecode to machine specific language.
Q 26. Which of the following options is the best for generating random integer 0 or 1?
(int)Math.random()
(int)Math.random()+1
(int)(Math.random()+0.5)
(int)(Math.random()+0.2)
Correct Answer & Explanation: c
random() is a static method defined in Math class. Syntax: static double random() random() always returns a value in the range 0.0 1 to 1.99 that will be '1' when typecasted to int. not selected.
Q 27. What will be the output of the program? public class Test { public static void main(String [] args) { signed int x = 10; for (int y=0; y<5; y++, x--) System.out.print(x + ", "); } }
9,8,7,6,5
Compilation fails
An exception is thrown at runtime
Correct Answer & Explanation: c
The word "signed" is not a valid modifier keyword in the Java language. All number primitives in Java are signed. Hence the Compilation will fail.
Q 28. Which two of the following methods are defined in class Thread? (i) start() (ii) wait() (iii)notify() iv)run() v)terminate()
i & iv
ii & iii
iii & iv
ii & iv
Correct Answer & Explanation: a
i & iv because only start() and run() are defined by the Thread class.
Q 29. Which is true about a method-local inner class?
It must be marked final.
It can be marked abstract.
It can be marked public.
It can be marked static.
Correct Answer & Explanation: b
Because a method-local inner class can be abstract, although it means a subclass of the inner class must be created if the abstract class is to be used (so an abstract method-local inner class is probably not useful).
Q 30. Which of these keywords can be used to prevent method overriding?
Static
Constant
Protected
Final
Correct Answer & Explanation: d
To disallow a method from being overridden specify final as a modifier at the start of its declaration.
Advance Java Placement Questions
Q 31. which of these class is super class of every class in java?
String
Object
Abstract
Array list
Correct Answer & Explanation: b
Object class is super class of every class in Java.
Q 32. Which operator is used to invert all the digits in binary representation of a number ?
~
<<<
>>>
^
Correct Answer & Explanation: a
Unary not operator ~ inverts all of the bits of its operant in binary representation.
Q 33. What is the output of relational operators?
Integer
Boolean
Characters
Double
Correct Answer & Explanation:b
Q 34. Which of these have highest precedence?
()
"++"
*
>>
Correct Answer & Explanation: a
Order of precedence is (Highest to lowest) A> B > C > D
Q 35. Which of the following is a superclass of all exception type classes?
Catchable
RuntimeExceptions
String
Throwable
Correct Answer & Explanation: d
Throwable is built in class and all exception type are subclass of this class.
Q 36. Which of these keywords are used for the block to handle the exceptions generated by try block?
Try
Catch
Throw
Check
Correct Answer & Explanation: b
Q 37. Which of these are types of multitasking?
Process based
Thread based
Process and thread based
None of the above
Correct Answer & Explanation:c
There are two types of multitasking: Process based multitasking and thread based multitasking.
Q 38. What does not prevent JVM from terminating?
Process
Daemon thread
User thread
JVM thread
Correct Answer & Explanation: b
Daemon thread runs in the background and does not prevent JVM from terminating
Q 39. What is the output of this program? class Abc { public static void main(String[]args) { String[] elements = {“for”,”tea”,”too”}; String first =(elements.length>0)? } }
Compilation error
An exception is thrown at runtime
The variable first is set to elements[0]
Correct Answer & Explanation: d
The value at the 0th position will be assigned to the variable first.
Q 40. All the variables of interface should be
Default and final
Default and static
Public, static and final
None of the above
Correct Answer & Explanation: c
Variables of an interface are public, static and final by default because the interface cannot be instantiated.
Q 41. Which of these method is given parameter via command line arguments?
main()
Recursive()method
Any method
None of the above
Correct Answer & Explanation: a
Only main() method can be given parameters via using command line arguments.
Q 42. Which of these packages contains the exception Stack Overflow in Java?
java.lang
java.util
java.system
Correct Answer & Explanation: a
java.lang contains the Stack Overflow in Java.
Q 43. What is the use if interpreter?
They convert bitecode to machine code.
They read high level code and execute them.
They are intermediated between JIT and JVM.
It is a synonym of JIT.
Correct Answer & Explanation: b
They read high level language and execute the program. Interpreters are normally not passing through bitecode and JIT compilation.
Q 44. Which of these handles the exception when no catch is used?
Default handler
Finally
Throw Handler
Java Runtime System
Correct Answer & Explanation: a
Q 45. What exception throw by parseInt() method?
ArithmeticExecption
ClassNotFoundExecption
NullPointerExecption
NumberFormatExecption
Correct Answer & Explanation: d
parseInt()Method parses input into integer. The exception thrown by this method is number format exception.
Q 46. What is the premise of equality for IdentityHashMap?
Reference Equality
Name equality
Hashcode equality
Length equality
Correct Answer & Explanation: a
IdentityHashMap is rarely used as it violates the basic contact of implementing equals() and HashCode method().
Q 47. How to sort elements of Arraylist?
Collection.sort(listObj);
Collections.sort(listObj);
listObj.sort();
Sorter.sortAsc(listObj);
Correct Answer & Explanation: b
Collections provide a method to sort the list. The order of sorting can be defined using Comparator.
Q 48. Which of these method of Object class is used to obtain class of an object at run time?
get()
void getclass()
Class getclass()
None of the mentioned
Correct Answer & Explanation: c
Class getclass() is used to obtain class of an object at run time.
These Java interview questions would give you an insight into what kind of questions could be asked.
Free Practice Tests
Most Important Interview Questions
Last Minute Class Notes