0% found this document useful (0 votes)
2 views7 pages

50 mcqs

The document contains a series of multiple-choice questions covering key concepts in Java programming, including encapsulation, inheritance, polymorphism, abstract classes, interfaces, input handling, arrays, and exception handling. Each question is followed by options, with the correct answers indicated. The content serves as a study guide or quiz for individuals learning Java.

Uploaded by

khadijanasir1607
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views7 pages

50 mcqs

The document contains a series of multiple-choice questions covering key concepts in Java programming, including encapsulation, inheritance, polymorphism, abstract classes, interfaces, input handling, arrays, and exception handling. Each question is followed by options, with the correct answers indicated. The content serves as a study guide or quiz for individuals learning Java.

Uploaded by

khadijanasir1607
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

🔐 Encapsulation & Abstraction

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

🧬 Abstract Classes & Interfaces


16. Which of the following is true about interfaces?
a) Can have instance variables
b) Can be instantiated
c) Can contain default methods ✅
d) Must contain constructors
17. Can a class implement multiple interfaces?
a) Yes ✅
b) No
c) Only abstract classes
d) Only if static methods are used
18. Can an abstract class implement an interface?
a) Yes ✅
b) No
c) Only if all methods are overridden
d) Only static methods allowed
19. Which can have constructors: interface or abstract class?
a) Interface
b) Abstract class ✅
c) Both
d) None
20. Which is true for interfaces in Java 8 and later?
a) They can have constructors
b) They can have static and default methods ✅
c) They cannot have any methods
d) Only abstract methods allowed

📥 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

⚙️ Static, Final & Miscellaneous


31. What does the static keyword denote?
a) Thread-safe code
b) Method belongs to object
c) Method/field belongs to class ✅
d) Private method
32. Which variable can be accessed without creating an object?
a) static ✅
b) final
c) instance
d) global
33. Which of these will compile?
a) final int a;
b) final int a = 10; ✅
c) final a = 10;
d) int final a = 10;
34. Which keyword is used to prevent a class from being inherited?
a) static
b) final ✅
c) private
d) super
35. Which class method can be called without creating an instance?
a) Instance method
b) Static method ✅
c) Final method
d) Abstract method

🧬 Conceptual & Logical Reasoning


36. Which principle hides internal details of an object?
a) Abstraction ✅
b) Inheritance
c) Polymorphism
d) Encapsulation
37. Can constructors be inherited in Java?
a) Yes
b) No ✅
c) Only if abstract
d) Only if private
38. Which OOP principle promotes code reuse?
a) Polymorphism
b) Encapsulation
c) Inheritance ✅
d) Abstraction
39. Which method is always called when an object is created?
a) main()
b) init()
c) Constructor ✅
d) run()
40. What is the output of: System.out.println("2" + 2 + 2);
a) 6
b) 222 ✅
c) 8
d) 2+2+2

🧬 Tricky Practice MCQs


41. Which is true about constructors?
a) They have return type
b) They must match class name ✅
c) They are static
d) They can be final
42. Which modifier is not allowed for constructors?
a) public
b) private
c) protected
d) static ✅
43. Which method is used to check object type?
a) equals()
b) getClass()
c) instanceof ✅
d) compareTo()
44. What is the default value of an uninitialized boolean[] element?
a) null
b) false ✅
c) true
d) 0
45. Which is not a valid loop in Java?
a) for
b) while
c) repeat ✅
d) do-while
46. What will be the result of System.out.println(10/0);?
a) 0
b) Infinity
c) ArithmeticException ✅
d) Compile error
47. Which exception must be caught or declared?
a) NullPointerException
b) IOException ✅
c) ArithmeticException
d) ArrayIndexOutOfBoundsException
48. Which method of Thread is used to start execution?
a) start() ✅
b) run()
c) execute()
d) launch()
49. What is the return type of main() in Java?
a) void ✅
b) int
c) boolean
d) String
50. Which type of polymorphism is shown when an object is referred using parent class
reference?
a) Compile-time
b) Runtime ✅
c) Static
d) Hidden

You might also like