50 mcqs
50 mcqs
1. Which access modifier ensures that a class member is accessible only within its own
class?
a) public
b) protected
c) private ✅
d) default
2. What is the main advantage of encapsulation?
a) Better performance
b) Global data access
c) Controlled access to class members ✅
d) None of the above
3. Which keyword is used to define an abstract class?
a) interface
b) abstract ✅
c) class
d) final
4. Can we instantiate an abstract class directly?
a) Yes
b) No ✅
c) Only in constructors
d) Only using interfaces
5. Which of the following can be a part of an abstract class?
a) Only abstract methods
b) Only constructors
c) Abstract and non-abstract methods ✅
d) Only static methods
🧬 Inheritance
6. Which keyword is used for inheritance in Java?
a) inherits
b) extends ✅
c) super
d) this
7. Which type of inheritance is not directly supported by Java classes?
a) Multilevel
b) Single
c) Multiple (via classes) ✅
d) Hierarchical
8. What happens if you do not call super() in a subclass constructor?
a) Compilation error
b) Java inserts it automatically ✅
c) Runtime error
d) Nothing
9. Which of the following allows access to the superclass methods?
a) this
b) super ✅
c) base
d) parent
10. What does super() do in a subclass constructor?
a) Calls its own constructor
b) Calls the superclass constructor ✅
c) Declares the parent method
d) Hides the constructor
🔁 Polymorphism
11. What is polymorphism?
a) Overriding only
b) Multiple classes
c) Same method with different behavior ✅
d) Object duplication
12. Which is compile-time polymorphism?
a) Method overloading ✅
b) Method overriding
c) Interface implementation
d) Final methods
13. Which is runtime polymorphism?
a) Static methods
b) Overriding ✅
c) Overloading
d) Constructor chaining
14. Which of the following is method overloading?
a) Same name, same parameters
b) Same name, different parameters ✅
c) Different name, same class
d) None
15. Which keyword prevents method overriding?
a) static
b) final ✅
c) abstract
d) private
📥 Input Handling
21. Which class is used for reading input from the user in the console?
a) BufferedReader
b) Scanner ✅
c) FileReader
d) StreamReader
22. Which method of Scanner reads a full line?
a) next()
b) readLine()
c) nextLine() ✅
d) input()
23. Which exception occurs on invalid numeric input using Scanner?
a) IOException
b) InputMismatchException ✅
c) RuntimeException
d) NullPointerException
24. What is the package of the Scanner class?
a) java.io
b) java.util ✅
c) java.lang
d) java.net
25. Which Scanner method checks if the next token is an int?
a) nextInt()
b) hasNextInt() ✅
c) isInt()
d) scanInt()
🧬 Arrays
26. What is the index of the first element in an array?
a) 0 ✅
b) 1
c) -1
d) It depends
27. Which is correct syntax to declare and initialize an array?
a) int[] a = {1,2,3}; ✅
b) int a[] = new int[];
c) int a[3] = new int[];
d) int a = new int[3];
28. What is arr.length in Java?
a) Method
b) Field/property ✅
c) Static method
d) Loop counter
29. What is printed by: System.out.println(new int[]{1,2,3}[1]);
a) 1
b) 2 ✅
c) 3
d) Compilation error
30. Which exception is thrown if you access index 100 in array of size 10?
a) NullPointerException
b) ArrayIndexOutOfBoundsException ✅
c) IndexOutOfMemoryError
d) RuntimeException