Top 15 MCQs of Java : You must know

Java is one of the most widely used programming languages in the world. It is used for developing a variety of applications, from mobile apps to enterprise software. As a result, it is a highly sought-after skill in the job market. If you are preparing for a Java-related interview, you will likely encounter multiple-choice questions (MCQs) about the language.
To help you prepare, we have compiled a list of the top 15 MCQs of Java that are asked most of the time. These questions cover a range of topics, from basic syntax to advanced concepts, and will give you a good idea of what to expect in your interview

- What is the default value of a local variable in Java?
A) null
B) 0
C) undefined
D) not assigned
Answer: D) not assigned
- Which of the following is not a valid identifier in Java?
A) variable
B) $variable
C) _variable
D) variable#
Answer: D) variable#
- What is the output of the following code?
int y = 10;
System.out.println(x + y + ” is the total”);
A) 15 is the total
B) 510 is the total
C) is the total 15
D) Compilation error
Answer: A) 15 is the total
- Which of the following is not a legal type in Java?
A) int
B) double
C) boolean
D) string
Answer: D) string
- Which of the following is not a valid control statement in Java?
A) if-else
B) switch
C) while
D) repeat
Answer: D) repeat
- What is the output of the following code?
int y = 10;
x = x + y;
System.out.println(x);
A) 5
B) 10
C) 15
D) 20
Answer: C) 15
- What is the difference between a static and non-static method in Java?
A) A static method belongs to the class and can be invoked without creating an instance, while a non-static method belongs to an instance and must be invoked on an instance.
B) A static method belongs to an instance and can be invoked without creating an instance, while a non-static method belongs to the class and must be invoked on an instance.
C) A static method belongs to an instance and can be invoked on an instance, while a non-static method belongs to the class and must be invoked without creating an instance.
D) A static method belongs to the class and can be invoked on an instance, while a non-static method belongs to an instance and must be invoked without creating an instance.
Answer: A) A static method belongs to the class and can be invoked without creating an instance, while a non-static method belongs to an instance and must be invoked on an instance.
- What is the use of the “this” keyword in Java?
A) to refer to the instance variables of the current class
B) to refer to the static variables of the current class
C) to refer to the local variables of the current class
D) to refer to the global variables of the current class
Answer: A) to refer to the instance variables of the current class
- What is the use of the “final” keyword in Java?
A) to indicate that a variable cannot be reassigned
B) to indicate that a method cannot be overridden
C) to indicate that a class cannot be inherited
D) All of the above
Answer: D) All of the above
You might be interested:
- What is the difference between a constructor and a method in Java?
A) A constructor is used to initialize an object, while a method is used to perform a specific action on an object.
B) A constructor is used to perform a specific action on an object, while a method is used to initialize an object.
C) A constructor is a special method, while a method is a regular method.
D) A constructor is used to create an object, while a method is used to destroy an object.
Answer: A) A constructor is used to initialize an object, while a method is used to perform a specific action on an object.
- What is the difference between an interface and an abstract class in Java?
A) An interface can have only abstract methods, while an abstract class can have both abstract and concrete methods.
B) An interface can have only static methods, while an abstract class can have both static and non-static methods.
C) An interface can have only final variables, while an abstract class can have both final and non-final variables.
D) An interface can be inherited by multiple classes, while an abstract class can be inherited by only one class.
Answer: A) An interface can have only abstract methods, while an abstract class can have both abstract and concrete methods.
- What is the use of the “final” keyword in Java?
A) to indicate that a variable cannot be reassigned
B) to indicate that a method cannot be overridden
C) to indicate that a class cannot be inherited
D) All of the above
Answer: D) All of the above
- What is the difference between a static and non-static method in Java?
A) A static method belongs to the class and can be invoked without creating an instance, while a non-static method belongs to an instance and must be invoked on an instance.
B) A static method belongs to an instance and can be invoked without creating an instance, while a non-static method belongs to the class and must be invoked on an instance.
C) A static method belongs to an instance and can be invoked on an instance, while a non-static method belongs to the class and must be invoked without creating an instance.
D) A static method belongs to the class and can be invoked on an instance, while a non-static method belongs to an instance and must be invoked without creating an instance.
Answer: A) A static method belongs to the class and can be invoked without creating an instance, while a non-static method belongs to an instance and must be invoked on an instance.
- What is the difference between “throw” and “throws” in Java?
A) “throw” is used to throw an exception, while “throws” is used to declare an exception.
B) “throws” is used to throw an exception, while “throw” is used to declare an exception.
C) “throw” is used to catch an exception, while “throws” is used to declare an exception.
D) “throws” is used to catch an exception, while “throw” is used to declare an exception.
Answer: A) “throw” is used to throw an exception, while “throws” is used to declare an exception.
- What is the use of the “this” keyword in Java?
A) to refer to the instance variables of the current class
B) to refer to the static variables of the current class
C) to refer to the local variables of the current class
D) to refer to the global variables of the current class
Answer: A) to refer to the instance variables of the current class
- What is the difference between “public” and “private” access modifiers in Java?
A) “public” members can be accessed by any code, while “private” members can only be accessed within the same class
B) “private” members can be accessed by any code, while “public” members can only be accessed within the same class
C) “public” members can be accessed only by subclasses, while “private” members can be accessed by any code
D) “private” members can be accessed only by subclasses, while “public” members can be accessed by any code
Answer: A) “public” members can be accessed by any code, while “private” members can only be accessed within the same class
- What is the difference between “extends” and “implements” in Java?
A) “extends” is used to inherit from a class, while “implements” is used to implement an interface
B) “implements” is used to inherit from a class, while “extends” is used to implement an interface
C) “extends” is used to inherit from an interface, while “implements” is used to implement a class
D) “implements” is used to inherit from an interface, while “extends” is used to implement a class
Answer: A) “extends” is used to inherit from a class, while “implements” is used to implement an interface
- What is the difference between “ArrayList” and “LinkedList” in Java?
A) “ArrayList” is an array-based implementation of a list, while “LinkedList” is a linked-based implementation of a list
B) “LinkedList” is an array-based implementation of a list, while “ArrayList” is a linked-based implementation of a list
C) “ArrayList” is faster than “LinkedList”, while “LinkedList” uses less memory than “ArrayList”
D) “LinkedList” is faster than “ArrayList”, while “ArrayList” uses less memory than “LinkedList”
Answer: A) “ArrayList” is an array-based implementation of a list, while “LinkedList” is a linked-based implementation of a list
- What is the difference between “==” and “equals” in Java?
A) “==” compares the memory addresses of two objects, while “equals” compares the values of the objects.
B) “==” compares the values of two objects, while “equals” compares the memory addresses of the objects.
C) “==” compares the type of two objects, while “equals” compares the value of the objects.
D) “==” compares the value of primitive data types, while “equals” compares the reference of objects.
Answer: A) “==” compares the memory addresses of two objects, while “equals” compares the values of the objects.
Conclusion
In conclusion, the top 19 MCQs of Java that we have outlined in this blog post cover a wide range of topics and are commonly asked in interviews. These questions are designed to test your understanding of the basics of the language, as well as your ability to apply that knowledge to solve problems. By familiarizing yourself with these questions, you will be better prepared to tackle any Java-related questions that come your way in an interview.
However, it is important to note that the questions above are not the only ones that you will be asked in an interview, it is also important to have a strong understanding of the language and its features so that you can answer any question that may be thrown your way. With the right preparation, you can feel confident and secure in your abilities when it comes time for your interview.
Thanks for reading! 🙂
You might be interested: