Latest Java OOP MCQs

1 min read

Object-Oriented Programming (OOP) is the core paradigm underlying Java, designed to organize software design around data, or objects, rather than functions and logic. The Java OOP model rests on four fundamental pillars: encapsulation, inheritance, polymorphism, and abstraction. By utilizing classes as blueprints, Java allows developers to create modular, reusable, and maintainable code structures. Features like dynamic method dispatch enable runtime polymorphism, while access modifiers and interfaces provide robust data hiding and contract-based design. Mastering these principles is absolutely critical for building enterprise-grade Java applications and succeeding in technical software engineering interviews.

1. Which of the following is NOT a fundamental principle of Object-Oriented Programming in Java?

a) Encapsulation
b) Inheritance
c) Polymorphism
d) Compilation
Correct Answer: d) Compilation
Explanation:
Compilation is a phase of transforming source code to bytecode. The four main OOP principles are Encapsulation, Inheritance, Polymorphism, and Abstraction.

2. What is an object in Java?

a) A blueprint from which individual classes are created
b) An instance of a class that has state and behavior
c) A keyword used to create instances
d) A special primitive data type
Correct Answer: b) An instance of a class that has state and behavior
Explanation:
An object is a runtime entity with its own state (fields) and behavior (methods), instantiated from a class template.

3. Which keyword is used to allocate memory for a new object in Java?

a) allocate
b) create
c) new
d) object
Correct Answer: c) new
Explanation:
The 'new' keyword instantiates a class by dynamically allocating memory for a new object at runtime.

4. Which of the following best describes a class in Java?

a) A physical entity in memory
b) A logical template or blueprint used to create objects
c) A runtime environment
d) An execution thread
Correct Answer: b) A logical template or blueprint used to create objects
Explanation:
A class is a logical blueprint that defines the variables and methods common to all objects of a certain kind.

5. Where are objects stored in the Java memory model?

a) Stack memory
b) Heap memory
c) Register memory
d) Cache memory
Correct Answer: b) Heap memory
Explanation:
In Java, objects and their instance variables are stored in the Heap memory space.

6. What is the term for data associated with a specific object?

a) State
b) Identity
c) Behavior
d) Action
Correct Answer: a) State
Explanation:
The 'state' of an object is represented by its fields or properties (instance variables) at any given moment.

7. What represents the 'behavior' of an object in Java?

a) Instance variables
b) Constructors
c) Methods
d) Packages
Correct Answer: c) Methods
Explanation:
Methods define the behavior or actions that an object can perform and how it can interact with its data.

8. What happens if you do not define any constructor for a class?

a) Compilation fails
b) The compiler automatically provides a default, no-argument constructor
c) A runtime exception is thrown during instantiation
d) The class cannot be instantiated
Correct Answer: b) The compiler automatically provides a default, no-argument constructor
Explanation:
If no constructors are explicitly written, the Java compiler injects a default, no-parameter constructor.

9. Which statement about constructors is true?

a) Constructors can have a return type like void
b) Constructors must have the exact same name as the class
c) Constructors can be inherited
d) Constructors are used to destroy objects
Correct Answer: b) Constructors must have the exact same name as the class
Explanation:
A constructor must exactly match the class name and must not have an explicit return type, not even void.

10. Can we overload a constructor in Java?

a) Yes, by providing multiple constructors with different parameter lists
b) Yes, by changing the return type of the constructor
c) No, a class can have only one constructor
d) No, constructors cannot be overloaded, only methods can
Correct Answer: a) Yes, by providing multiple constructors with different parameter lists
Explanation:
Constructor overloading is perfectly valid and is achieved by declaring multiple constructors with different parameter signatures.

11. What is Encapsulation?

a) Acquiring properties of one class into another
b) Hiding the implementation details and showing only functionality
c) Wrapping data and code acting on the data into a single unit
d) Providing multiple implementations for a single interface
Correct Answer: c) Wrapping data and code acting on the data into a single unit
Explanation:
Encapsulation binds data and the methods that operate on that data into a single capsule, usually by making fields private and providing public getters/setters.

12. How is data hiding primarily achieved in Java?

a) Using the 'final' keyword
b) Using the 'private' access modifier for instance variables
c) Using abstract classes
d) Using the 'static' keyword
Correct Answer: b) Using the 'private' access modifier for instance variables
Explanation:
By declaring variables as private, they cannot be accessed directly outside the class, thereby achieving data hiding.

13. Which access modifier provides the widest accessibility in Java?

a) public
b) protected
c) default
d) private
Correct Answer: a) public
Explanation:
The 'public' modifier allows a class, method, or variable to be accessed from any other class in any package.

14. What is the accessibility of a member marked as 'protected'?

a) Accessible everywhere
b) Accessible only within the same class
c) Accessible within the same package and subclasses outside the package
d) Accessible only within subclasses in the same package
Correct Answer: c) Accessible within the same package and subclasses outside the package
Explanation:
Protected members are visible to all classes in the same package, and to subclasses regardless of the package they belong to.

15. If no access modifier is specified for a variable, what is its default accessibility?

a) public
b) private
c) protected
d) package-private (default)
Correct Answer: d) package-private (default)
Explanation:
Without an explicit modifier, a member assumes package-private visibility, meaning it is accessible only to classes within the same package.

16. What is Inheritance in OOP?

a) A process where one object acquires the properties and behaviors of a parent object
b) A mechanism to hide complex logic
c) The ability to have multiple methods with the same name
d) Wrapping internal state into a single module
Correct Answer: a) A process where one object acquires the properties and behaviors of a parent object
Explanation:
Inheritance allows a new class (subclass) to absorb the attributes and methods of an existing class (superclass), promoting code reusability.

17. Which keyword is used to establish inheritance between two classes?

a) implements
b) inherits
c) extends
d) super
Correct Answer: c) extends
Explanation:
The 'extends' keyword is used by a class to inherit from a superclass.

18. Does Java support multiple inheritance with classes?

a) Yes, a class can extend multiple classes directly
b) Yes, but only if they are abstract classes
c) No, it causes the diamond problem, so it is unsupported for classes
d) No, Java does not support any form of multiple inheritance
Correct Answer: c) No, it causes the diamond problem, so it is unsupported for classes
Explanation:
To prevent ambiguity known as the diamond problem, Java only allows a class to extend one parent class. Multiple inheritance is achieved through interfaces.

19. What is the root class of all classes in Java?

a) java.lang.System
b) java.lang.Object
c) java.lang.Class
d) java.lang.Root
Correct Answer: b) java.lang.Object
Explanation:
Every class in Java implicitly or explicitly extends the java.lang.Object class, making it the root of the Java class hierarchy.

20. Which type of inheritance is represented when Class B extends Class A, and Class C extends Class B?

a) Single inheritance
b) Multiple inheritance
c) Multilevel inheritance
d) Hierarchical inheritance
Correct Answer: c) Multilevel inheritance
Explanation:
A chain of inheritance where a subclass itself becomes the superclass for another class is known as multilevel inheritance.

21. What is the primary purpose of the 'super' keyword?

a) To define a class as a parent class
b) To refer to the immediate parent class instance variable, method, or constructor
c) To bypass encapsulation rules
d) To invoke static methods of a class
Correct Answer: b) To refer to the immediate parent class instance variable, method, or constructor
Explanation:
The 'super' reference variable accesses members of the immediate parent class, especially useful when subclass members hide parent members.

22. How do you invoke a parent class's constructor from a subclass?

a) parent()
b) super()
c) this()
d) base()
Correct Answer: b) super()
Explanation:
The 'super()' call invokes the parent class constructor. It must be the very first statement inside the subclass constructor.

23. Which of the following is true about constructor inheritance?

a) Constructors are inherited exactly like methods
b) Only default constructors are inherited
c) Constructors are not inherited by subclasses
d) Constructors are inherited but cannot be overridden
Correct Answer: c) Constructors are not inherited by subclasses
Explanation:
Constructors are not members of a class in the same way methods are, so they are not inherited. However, subclass constructors implicitly invoke the parent's no-arg constructor.

24. What is Polymorphism in Java?

a) Hiding data completely from the end user
b) The ability of an object to take on many forms
c) Creating objects without the new keyword
d) Preventing a class from being inherited
Correct Answer: b) The ability of an object to take on many forms
Explanation:
Polymorphism (many forms) allows a single action to behave differently based on the object that is invoking it.

25. Which concept is an example of compile-time polymorphism?

a) Method Overriding
b) Method Overloading
c) Dynamic Binding
d) Upcasting
Correct Answer: b) Method Overloading
Explanation:
Method overloading is resolved at compile time (early binding) by matching the method signature.

26. Which concept is an example of run-time polymorphism?

a) Method Overriding
b) Method Overloading
c) Constructor Overloading
d) Static Method Invocation
Correct Answer: a) Method Overriding
Explanation:
Method overriding is resolved dynamically at runtime based on the actual object type, known as late binding.

27. What are the requirements for Method Overloading?

a) Methods must have different return types
b) Methods must have the same name and the exact same parameters
c) Methods must have the same name but different parameter lists
d) Methods must be in a parent and child class
Correct Answer: c) Methods must have the same name but different parameter lists
Explanation:
Overloading occurs in the same class when methods share a name but differ in the number, type, or sequence of parameters.

28. What are the rules for Method Overriding?

a) The method must have the same name, same parameters, and be in a child class
b) The method must have different parameters in a child class
c) The method must have the same name but can be in the same class
d) The method must throw broader checked exceptions
Correct Answer: a) The method must have the same name, same parameters, and be in a child class
Explanation:
Overriding requires the same method signature (name and parameters) as the parent class method, providing a specific implementation.

29. Can we override a 'static' method in Java?

a) Yes, static methods override exactly like instance methods
b) No, static methods belong to the class and are hidden, not overridden
c) Yes, but only if they are public
d) No, static methods cause compilation errors in child classes
Correct Answer: b) No, static methods belong to the class and are hidden, not overridden
Explanation:
If a subclass defines a static method with the same signature as a superclass static method, it hides the superclass method; this is called Method Hiding, not Overriding.

30. Can we override a 'private' method?

a) Yes, if accessed via a public method
b) No, private methods are not visible to subclasses
c) Yes, but only within the same package
d) No, unless we use the @Override annotation
Correct Answer: b) No, private methods are not visible to subclasses
Explanation:
Private methods are bound to their class and are entirely invisible to child classes, making overriding impossible.

31. What is 'covariant return type' in method overriding?

a) Changing the return type to an entirely unrelated type
b) Changing the return type of the overriding method to a subclass type of the original return type
c) Changing a method from returning void to returning int
d) Using generics to return any object type
Correct Answer: b) Changing the return type of the overriding method to a subclass type of the original return type
Explanation:
Since Java 5.0, an overridden method can return a subtype of the type returned by the overridden method, ensuring type safety.

32. Which keyword restricts a class from being inherited?

a) static
b) abstract
c) final
d) private
Correct Answer: c) final
Explanation:
Marking a class as 'final' prevents any other class from extending it. E.g., the String class is final.

33. What does 'final' applied to a method mean?

a) The method cannot be overloaded
b) The method cannot be overridden by subclasses
c) The method returns a constant value
d) The method must be executed last
Correct Answer: b) The method cannot be overridden by subclasses
Explanation:
A final method cannot be modified or overridden by any child class, securing its implementation.

34. What is Abstraction in Java?

a) Providing all implementation details publicly
b) Creating objects using factories
c) Hiding internal implementation details and showing only essential features
d) Combining different classes into one module
Correct Answer: c) Hiding internal implementation details and showing only essential features
Explanation:
Abstraction focuses on what an object does instead of how it does it, reducing complexity for the user.

35. How is Abstraction implemented in Java?

a) Using only private fields
b) Using abstract classes and interfaces
c) Using method overriding
d) Using final classes
Correct Answer: b) Using abstract classes and interfaces
Explanation:
Abstract classes provide partial abstraction, while interfaces (traditionally) provide 100% abstraction.

36. Which of the following is true about abstract classes?

a) They can be instantiated using the 'new' keyword
b) They must have at least one abstract method
c) They cannot be instantiated
d) They cannot have constructors
Correct Answer: c) They cannot be instantiated
Explanation:
Abstract classes are incomplete blueprints. They are designed to be inherited, not instantiated directly.

37. Can an abstract class have constructors?

a) No, because they cannot be instantiated
b) Yes, to initialize variables declared in the abstract class when a subclass is instantiated
c) Yes, but they must be declared static
d) No, it causes a compile-time error
Correct Answer: b) Yes, to initialize variables declared in the abstract class when a subclass is instantiated
Explanation:
Abstract classes can have constructors. They are called implicitly when a concrete subclass is instantiated to set up inherited state.

38. What is an abstract method?

a) A method with a complete body but restricted access
b) A method declared without a body, ending with a semicolon
c) A method that cannot be overridden
d) A method that must return void
Correct Answer: b) A method declared without a body, ending with a semicolon
Explanation:
Abstract methods lack an implementation (body). The subclass is forced to provide the implementation.

39. Is it mandatory for an abstract class to have abstract methods?

a) Yes, at least one abstract method is required
b) No, an abstract class can have zero abstract methods
c) Yes, all methods must be abstract
d) No, but it must implement an interface
Correct Answer: b) No, an abstract class can have zero abstract methods
Explanation:
You can declare a class abstract even if it has no abstract methods, purely to prevent direct instantiation.

40. What happens if a class extends an abstract class but does not implement all its abstract methods?

a) The code compiles but throws an error at runtime
b) The compiler ignores the unimplemented methods
c) The subclass itself must be declared abstract
d) The methods are given a default empty body by the compiler
Correct Answer: c) The subclass itself must be declared abstract
Explanation:
If a child class fails to implement inherited abstract methods, it remains incomplete and must also be marked abstract.

41. What is an interface in Java?

a) A class with only static methods
b) A contract that completely hides implementation details, traditionally containing only abstract methods
c) A final class that cannot be inherited
d) A tool to create GUI components
Correct Answer: b) A contract that completely hides implementation details, traditionally containing only abstract methods
Explanation:
An interface specifies a set of methods that a class must implement, defining 'what' to do without dictating 'how'.

42. Which keyword allows a class to adhere to an interface?

a) extends
b) implements
c) inherits
d) interfaces
Correct Answer: b) implements
Explanation:
A class 'implements' an interface, committing to provide bodies for all its abstract methods.

43. Can a Java class implement multiple interfaces?

a) No, it violates the diamond problem rule
b) Yes, Java supports multiple inheritance of type through interfaces
c) Yes, but only if the interfaces have no methods
d) No, only abstract classes can implement multiple interfaces
Correct Answer: b) Yes, Java supports multiple inheritance of type through interfaces
Explanation:
While a class can extend only one parent class, it can implement any number of interfaces.

44. What are the default modifiers for variables defined inside an interface?

a) private final
b) protected static
c) public static final
d) default static
Correct Answer: c) public static final
Explanation:
All fields in an interface are implicitly public, static, and final (constants) by default.

45. What are the default modifiers for a method declared without a body in an interface?

a) public abstract
b) protected abstract
c) static abstract
d) private abstract
Correct Answer: a) public abstract
Explanation:
Methods without a body in an interface are implicitly public and abstract.

46. Since Java 8, can an interface have method bodies?

a) No, interfaces can never have method bodies
b) Yes, using the 'default' and 'static' keywords
c) Yes, but only if the interface is abstract
d) Yes, using the 'final' keyword
Correct Answer: b) Yes, using the 'default' and 'static' keywords
Explanation:
Java 8 introduced default and static methods in interfaces, allowing them to provide concrete implementations.

47. What is a Marker Interface in Java?

a) An interface with exactly one method
b) An interface with no methods or fields, used to indicate something to the compiler or JVM
c) An interface used solely for documentation
d) An interface with only default methods
Correct Answer: b) An interface with no methods or fields, used to indicate something to the compiler or JVM
Explanation:
Examples include Serializable and Cloneable. They tag a class to signal specific capabilities to the JVM.

48. What is a Functional Interface?

a) An interface containing completely implemented functions
b) An interface containing exactly one abstract method
c) An interface extending another functional interface
d) An interface with multiple abstract methods but one default method
Correct Answer: b) An interface containing exactly one abstract method
Explanation:
Functional interfaces (e.g., Runnable, Callable) have only one abstract method and are the basis for Lambda expressions in Java 8.

49. Which annotation is used to explicitly declare a functional interface?

a) @Function
b) @FunctionalInterface
c) @SingleMethodInterface
d) @LambdaInterface
Correct Answer: b) @FunctionalInterface
Explanation:
This annotation prevents accidental addition of multiple abstract methods, generating a compiler error if the rule is violated.

50. Can an interface extend another interface?

a) No, interfaces can only be implemented
b) Yes, using the 'implements' keyword
c) Yes, using the 'extends' keyword
d) Yes, using the 'super' keyword
Correct Answer: c) Yes, using the 'extends' keyword
Explanation:
An interface can extend one or more other interfaces, inheriting their abstract methods.

51. What does the 'this' keyword refer to in Java?

a) The parent class of the current object
b) The current instance of the class
c) A static context pointer
d) The thread executing the method
Correct Answer: b) The current instance of the class
Explanation:
The 'this' reference points to the specific object upon which a non-static method or constructor is being invoked.

52. Can 'this' be used inside a static method?

a) Yes, to reference static variables
b) No, because static methods don't belong to any specific instance
c) Yes, to refer to the class object
d) No, but 'super' can be used
Correct Answer: b) No, because static methods don't belong to any specific instance
Explanation:
Since static methods are class-level and called without creating instances, there is no 'this' object available.

53. What is constructor chaining?

a) Inheriting multiple constructors from interfaces
b) Calling one constructor from another constructor within the same class using this()
c) Creating multiple objects in a chain
d) Converting objects to strings
Correct Answer: b) Calling one constructor from another constructor within the same class using this()
Explanation:
Using 'this(parameters)', a constructor can call another overloaded constructor in the same class to avoid code duplication.

54. What is a 'static' variable?

a) A variable that cannot be changed once initialized
b) A variable shared among all instances of a class
c) A variable local to a method
d) A variable stored in CPU cache
Correct Answer: b) A variable shared among all instances of a class
Explanation:
Static variables belong to the class itself, meaning only one copy exists in memory, shared by all objects of that class.

55. When are static blocks executed?

a) Every time an object is created
b) Before constructors, but only when objects are created
c) When the class is loaded into memory by the classloader
d) Just before program termination
Correct Answer: c) When the class is loaded into memory by the classloader
Explanation:
Static initializer blocks run exactly once, at the time the JVM loads the class into memory.

56. Which of the following describes an association relationship?

a) IS-A relationship
b) HAS-A relationship
c) USES-A relationship
d) Both b and c
Correct Answer: d) Both b and c
Explanation:
Association defines a connection between classes. Composition and Aggregation (HAS-A) are forms of association.

57. What is Aggregation?

a) A strong HAS-A relationship where the child object cannot exist without the parent
b) A weak HAS-A relationship where the child object can exist independently of the parent
c) Inheriting behaviors from multiple parent classes
d) Hiding state from external entities
Correct Answer: b) A weak HAS-A relationship where the child object can exist independently of the parent
Explanation:
In aggregation (e.g., Department has Teachers), if the parent is destroyed, the child objects can still exist independently.

58. What is Composition?

a) A strong HAS-A relationship where child objects cannot exist independently of the parent
b) A weak association between objects
c) Combining multiple interfaces into one
d) Compiling Java code into bytecode
Correct Answer: a) A strong HAS-A relationship where child objects cannot exist independently of the parent
Explanation:
In composition (e.g., House has Rooms), if the House is destroyed, the Rooms are also destroyed.

59. Why favor Composition over Inheritance?

a) Inheritance requires more memory
b) Composition provides better encapsulation and prevents rigid, fragile class hierarchies
c) Composition runs faster at execution time
d) Inheritance doesn't support polymorphism
Correct Answer: b) Composition provides better encapsulation and prevents rigid, fragile class hierarchies
Explanation:
Composition allows dynamic behavior changes at runtime and avoids the tight coupling that inheritance enforces.

60. What is an Inner Class?

a) A class defined within the same file as another class
b) A class defined within the body of another class
c) A class in a sub-package
d) A subclass
Correct Answer: b) A class defined within the body of another class
Explanation:
Inner classes logically group classes that are only used in one place, increasing encapsulation and readability.

61. What is an Anonymous Inner Class?

a) An inner class that has no name, typically instantiated right where it is declared
b) An inner class without any methods
c) An interface that has no name
d) A class that removes its reference after execution
Correct Answer: a) An inner class that has no name, typically instantiated right where it is declared
Explanation:
Anonymous classes are used to instantiate objects with certain 'one-off' modifications without formally defining a new subclass.

62. What is Dynamic Method Dispatch?

a) The process of compiling multiple methods at once
b) The mechanism by which a call to an overridden method is resolved at runtime rather than compile time
c) Sending methods over a network
d) Loading classes dynamically
Correct Answer: b) The mechanism by which a call to an overridden method is resolved at runtime rather than compile time
Explanation:
This is the essence of runtime polymorphism in Java. The JVM determines the actual object type at runtime to invoke the correct overridden method.

63. What does Upcasting mean in Java?

a) Casting a superclass reference to a subclass type
b) Casting a primitive type to a wrapper class
c) Assigning a subclass object to a superclass reference variable
d) Upgrading the Java version
Correct Answer: c) Assigning a subclass object to a superclass reference variable
Explanation:
Upcasting (Parent p = new Child()) happens automatically and allows for polymorphic array collections and method parameters.

64. What does Downcasting mean in Java?

a) Assigning a subclass reference to a superclass object without explicit cast
b) Explicitly casting a superclass reference back to a subclass type
c) Converting a double to an int
d) Calling a parent method from a child
Correct Answer: b) Explicitly casting a superclass reference back to a subclass type
Explanation:
Downcasting (Child c = (Child) p) is required to access child-specific methods that are not declared in the parent reference type.

65. Which operator is safely used to check an object's type before downcasting?

a) typeof
b) instanceof
c) checktype
d) isA
Correct Answer: b) instanceof
Explanation:
The 'instanceof' operator tests whether an object is an instance of a specific class or interface, preventing ClassCastExceptions.

66. What exception is thrown if you improperly downcast an object?

a) NullPointerException
b) IllegalArgumentException
c) ClassCastException
d) TypeMismatchException
Correct Answer: c) ClassCastException
Explanation:
If the actual runtime object is not of the type you are attempting to cast it to, a ClassCastException is thrown.

67. Can constructors be marked as 'final'?

a) Yes, to prevent constructor overriding
b) No, constructors cannot be inherited, so making them final is illegal
c) Yes, but only in abstract classes
d) No, but they can be marked static
Correct Answer: b) No, constructors cannot be inherited, so making them final is illegal
Explanation:
Because constructors are not inherited, they can never be overridden, making the 'final' keyword on them logically useless and structurally illegal.

68. What is the primary characteristic of a Singleton class?

a) It can only be instantiated once per thread
b) It ensures that only one instance of the class is created in the JVM
c) It cannot have any variables
d) It can only have static methods
Correct Answer: b) It ensures that only one instance of the class is created in the JVM
Explanation:
Singleton limits instantiation to one object. It is typically implemented with a private constructor and a static getInstance method.

69. How do you enforce a Singleton design pattern structurally in a class?

a) Make the class final
b) Make all fields public
c) Declare the constructor as private
d) Extend the Singleton interface
Correct Answer: c) Declare the constructor as private
Explanation:
A private constructor prevents external classes from instantiating the class, forcing them to use the controlled static factory method.

70. What is an Enum in Java?

a) A simple list of strings
b) A special class that represents a group of constants (unchangeable variables)
c) A memory allocation mechanism
d) An alternative to interfaces
Correct Answer: b) A special class that represents a group of constants (unchangeable variables)
Explanation:
Enums are reference types that define a fixed set of constants. They can also have fields, constructors, and methods.

71. Can an Enum extend a regular class?

a) Yes, if the class is abstract
b) Yes, any class
c) No, because all enums implicitly extend java.lang.Enum
d) No, enums cannot extend anything, nor implement interfaces
Correct Answer: c) No, because all enums implicitly extend java.lang.Enum
Explanation:
Since Java does not support multiple class inheritance, and enums implicitly extend java.lang.Enum, they cannot extend another class. (They can implement interfaces).

72. What does the 'S' stand for in SOLID OOP principles?

a) Static Type Principle
b) Single Responsibility Principle
c) Solid State Principle
d) Standardized Output Principle
Correct Answer: b) Single Responsibility Principle
Explanation:
SRP states that a class should have one, and only one, reason to change, meaning it should only have one job or responsibility.

73. What does the Open/Closed Principle state?

a) Classes should be open to the public but closed to inheritance
b) Software entities should be open for extension, but closed for modification
c) Files should be opened securely and closed safely
d) Methods should be open to overriding but closed to overloading
Correct Answer: b) Software entities should be open for extension, but closed for modification
Explanation:
You should be able to add new functionality without altering existing, tested code, typically via inheritance and polymorphism.

74. What is meant by 'Tight Coupling'?

a) When a group of classes are highly dependent on one another
b) When variables are encapsulated properly
c) When code is compressed into a JAR file
d) When inheritance is not used
Correct Answer: a) When a group of classes are highly dependent on one another
Explanation:
Tight coupling implies changes in one class severely impact other classes. OOP design favors loose coupling via interfaces.

75. What does 'Cohesion' refer to in Object-Oriented design?

a) The degree to which different modules depend on each other
b) How fast a class compiles
c) The degree to which the elements inside a class belong together
d) The ability to inherit from multiple classes
Correct Answer: c) The degree to which the elements inside a class belong together
Explanation:
High cohesion means a class does exactly one defined job efficiently. Low cohesion means a class does many unrelated jobs.

76. What happens when you declare an instance variable as 'final'?

a) It can be modified only within subclasses
b) It must be initialized, and its value cannot be changed once assigned
c) It behaves like a static variable
d) It cannot be accessed outside the class
Correct Answer: b) It must be initialized, and its value cannot be changed once assigned
Explanation:
Final variables are constants; once they are assigned a value, it becomes immutable.

77. What is a 'Blank Final' variable?

a) A final variable assigned a null value
b) A final variable that is not initialized at the time of declaration
c) A final variable initialized in a static block
d) A final variable of type String
Correct Answer: b) A final variable that is not initialized at the time of declaration
Explanation:
A final variable not assigned a value upon declaration is a blank final variable. It must be initialized inside all constructors.

78. Which OOP concept represents the IS-A relationship?

a) Encapsulation
b) Composition
c) Inheritance
d) Abstraction
Correct Answer: c) Inheritance
Explanation:
When class Dog extends Animal, it is accurate to say 'Dog IS-A Animal', which represents inheritance.

79. What will happen if we try to instantiate an interface?

a) It returns null
b) It compiles successfully if all methods are static
c) A compilation error occurs
d) A runtime exception is thrown
Correct Answer: c) A compilation error occurs
Explanation:
Interfaces cannot be instantiated directly using 'new'. A class must implement it, and then the class can be instantiated.

80. What is the keyword used by a class to use an interface?

a) extends
b) includes
c) implements
d) imports
Correct Answer: c) implements
Explanation:
A class 'implements' an interface, ensuring it fulfills the contract set by the interface.

81. Can we overload the main method in Java?

a) No, it is the entry point of the application
b) Yes, we can overload it by passing different parameters
c) No, static methods cannot be overloaded
d) Yes, but the JVM will execute all main methods randomly
Correct Answer: b) Yes, we can overload it by passing different parameters
Explanation:
You can have multiple main methods with different parameter types, but the JVM will only auto-execute the standard public static void main(String[] args).

82. Which of these is NOT a valid access modifier in Java?

a) public
b) protected
c) internal
d) private
Correct Answer: c) internal
Explanation:
'internal' is an access modifier in languages like C#, but in Java, the equivalent package-private is achieved by using no modifier at all.

83. If Class A extends Class B, which constructor is executed first when Class A is instantiated?

a) Class A's constructor
b) Class B's constructor
c) Object class constructor
d) It happens simultaneously
Correct Answer: c) Object class constructor
Explanation:
Constructors execute from the top of the inheritance tree downwards. Object() runs, then Class B's, and finally Class A's.

84. What happens if a child class defines a variable with the same name as a variable in the parent class?

a) Variable overriding occurs
b) Variable hiding (Shadowing) occurs
c) A compile-time error occurs
d) The JVM crashes
Correct Answer: b) Variable hiding (Shadowing) occurs
Explanation:
Variables in Java are not polymorphic. The child class variable hides the parent class variable. Access depends on the reference type.

85. What happens to the methods of an interface if they are not explicitly declared public?

a) They become package-private
b) They throw a syntax error
c) They are implicitly public and abstract
d) They become protected
Correct Answer: c) They are implicitly public and abstract
Explanation:
By language specification, all standard methods in an interface are implicitly public and abstract.

86. What is the return type of a constructor?

a) void
b) The class type itself
c) int
d) None of the above
Correct Answer: d) None of the above
Explanation:
Constructors do not have a return type, not even void. Writing 'void' turns the constructor into a regular method.

87. What is the 'transient' keyword used for in Java objects?

a) To make a variable accessible to all threads
b) To mark a variable to be ignored during object serialization
c) To prevent garbage collection
d) To ensure immediate memory allocation
Correct Answer: b) To mark a variable to be ignored during object serialization
Explanation:
When an object is serialized, variables marked as 'transient' are not serialized and their values are lost (reset to defaults).

88. What is the purpose of the 'finalize' method?

a) To construct an object permanently
b) To prevent a class from being inherited
c) To perform cleanup operations before an object is garbage collected
d) To end a running thread
Correct Answer: c) To perform cleanup operations before an object is garbage collected
Explanation:
The finalize() method is called by the Garbage Collector before removing the object from memory, though its use is deprecated in modern Java.

89. Which feature of OOP helps achieve loose coupling?

a) Interfaces
b) Static variables
c) Private constructors
d) Final variables
Correct Answer: a) Interfaces
Explanation:
Interfaces allow components to interact without knowing each other's strict implementations, leading to loosely coupled code.

90. How do you prevent a specific method from being overridden without making the whole class final?

a) Mark the method as static
b) Mark the method as final
c) Mark the method as abstract
d) Omit access modifiers
Correct Answer: b) Mark the method as final
Explanation:
Applying the 'final' keyword to a method explicitly prevents any subclass from overriding it.

91. Can a class have multiple methods with the exact same signature?

a) Yes, if their return types differ
b) No, it results in a compile-time error
c) Yes, if they throw different exceptions
d) Yes, if one is static and the other is instance
Correct Answer: b) No, it results in a compile-time error
Explanation:
A method signature consists of the name and parameter list. A class cannot compile if it has two methods with identical signatures.

92. What is Object Cloning?

a) Copying references so two variables point to the same object
b) Creating an exact, independent copy of an object's state in a new memory location
c) Moving an object to another memory heap
d) Uploading an object to a database
Correct Answer: b) Creating an exact, independent copy of an object's state in a new memory location
Explanation:
Cloning creates a duplicate object. In Java, this is usually achieved by implementing the Cloneable interface and overriding clone().

93. In Java, 'Pass by Value' means what when passing objects to methods?

a) The actual object is copied and passed
b) A copy of the reference to the object is passed
c) The method cannot modify the object's internal state
d) The reference itself can be redirected to a new object entirely for the caller
Correct Answer: b) A copy of the reference to the object is passed
Explanation:
Java strictly uses pass-by-value. For objects, the value passed is a copy of the memory reference, meaning internal state can be mutated, but assigning a new object won't affect the original reference.

94. Which relationship represents dependency (where one class uses another temporarily)?

a) Composition
b) Aggregation
c) Association (Uses-A)
d) Inheritance
Correct Answer: c) Association (Uses-A)
Explanation:
Dependency often represents a 'Uses-A' relationship, where one object relies on another temporarily (e.g., as a method parameter).

95. What happens if a parent class constructor throws an exception?

a) The child class constructor ignores it
b) The child class constructor must declare or catch the exception
c) The program automatically terminates without compilation errors
d) Constructors cannot throw exceptions
Correct Answer: b) The child class constructor must declare or catch the exception
Explanation:
Because the child constructor implicitly calls the parent constructor, any checked exceptions thrown by the parent must be handled by the child.

96. What does a 'NullPointerException' imply in OOP context?

a) You are trying to divide by zero
b) You are trying to call a method or access a field on a reference that points to nothing (null)
c) The JVM is out of memory
d) A constructor was written incorrectly
Correct Answer: b) You are trying to call a method or access a field on a reference that points to nothing (null)
Explanation:
NPE occurs when the reference variable holds null but the program attempts to dereference it for state or behavior.

97. Can you define an interface inside a class?

a) No, interfaces must be top-level
b) Yes, this is known as a nested interface
c) Yes, but only if the class is abstract
d) No, interfaces can only hold other interfaces
Correct Answer: b) Yes, this is known as a nested interface
Explanation:
Nested interfaces are allowed. They are implicitly static and are typically used to group strongly related types.

98. What does a Factory Method pattern essentially do?

a) Destroys old objects
b) Delegates the responsibility of object instantiation to a specialized method
c) Prevents instantiation completely
d) Clones classes
Correct Answer: b) Delegates the responsibility of object instantiation to a specialized method
Explanation:
Factory methods return instances of objects, abstracting the 'new' keyword away from the client code to support flexibility.

99. Which of these concepts represents providing specialized behavior for a general method?

a) Polymorphism / Overriding
b) Encapsulation
c) Data Hiding
d) Garbage Collection
Correct Answer: a) Polymorphism / Overriding
Explanation:
Overriding a generalized parent method to provide specialized behavior in a subclass is a prime example of polymorphism.

100. How are variables of an interface accessed if they are static and final?

a) Using a child object
b) Directly using the Interface name (InterfaceName.variableName)
c) Using the 'super' keyword
d) They cannot be accessed externally
Correct Answer: b) Directly using the Interface name (InterfaceName.variableName)
Explanation:
Because they are static, interface constants are accessed statically using the interface's type name.

101. Can an abstract class extend a concrete (normal) class?

a) No, abstract classes can only extend other abstract classes
b) Yes, there is no restriction on this
c) No, abstract classes cannot inherit
d) Yes, but they cannot inherit concrete methods
Correct Answer: b) Yes, there is no restriction on this
Explanation:
An abstract class can perfectly extend a concrete class, gaining its implemented methods while possibly adding its own abstract ones.

102. When casting objects, which direction happens implicitly and safely?

a) Downcasting (Superclass to Subclass)
b) Upcasting (Subclass to Superclass)
c) Sidecasting (Sibling to Sibling)
d) Crosscasting (Object to Interface)
Correct Answer: b) Upcasting (Subclass to Superclass)
Explanation:
Since a subclass IS-A superclass, assigning it to a superclass reference (upcasting) is strictly type-safe and done implicitly by the compiler.

103. What is the 'Liskov Substitution Principle' (LSP)?

a) Interfaces should be segregated based on client needs
b) Objects of a superclass should be replaceable with objects of its subclasses without breaking the application
c) Classes must have single responsibility
d) High level modules shouldn't depend on low level modules
Correct Answer: b) Objects of a superclass should be replaceable with objects of its subclasses without breaking the application
Explanation:
LSP ensures that inheritance is used correctly, and that derived classes functionally honor the contract established by base classes.

104. Can an interface declare a constructor?

a) Yes
b) No, interfaces do not maintain state and cannot be instantiated directly
c) Yes, but it must be default
d) Yes, but only private constructors
Correct Answer: b) No, interfaces do not maintain state and cannot be instantiated directly
Explanation:
Since interfaces cannot hold instance state (fields), they do not have constructors to initialize anything.

105. Can an abstract class implement an interface without providing bodies for the interface methods?

a) Yes, it can leave the implementation to its concrete subclasses
b) No, any class implementing an interface must provide bodies
c) Yes, but only if the interface is also abstract
d) No, abstract classes cannot implement interfaces
Correct Answer: a) Yes, it can leave the implementation to its concrete subclasses
Explanation:
An abstract class can declare that it implements an interface, passing the burden of actual method implementation to the first concrete subclass.

106. Which keyword is used to access members hidden by variable shadowing?

a) hidden
b) this or super
c) parent
d) override
Correct Answer: b) this or super
Explanation:
If a local variable shadows an instance variable, 'this.var' accesses the instance. If a subclass variable shadows a parent's, 'super.var' accesses the parent's.

107. What is a 'POJO' in Java OOP context?

a) Private Object Java Order
b) Plain Old Java Object
c) Public Oriented Java Object
d) Primary Object Java Origin
Correct Answer: b) Plain Old Java Object
Explanation:
A POJO is a standard, unburdened Java object not bound by any special restriction, framework, or interface.

108. What is a Java Bean?

a) Any Java object
b) A POJO with private fields, public getters/setters, and a no-arg constructor
c) A framework for managing dependencies
d) An embedded server object
Correct Answer: b) A POJO with private fields, public getters/setters, and a no-arg constructor
Explanation:
Java Beans follow strict encapsulation and instantiation conventions, allowing them to be reusable and serializable.

109. What design pattern creates an interface exposing ways to create an object, but lets subclasses decide which class to instantiate?

a) Singleton
b) Observer
c) Factory Method
d) Decorator
Correct Answer: c) Factory Method
Explanation:
The Factory Method pattern defines an interface for creating objects, deferring the specific instantiation logic to subclasses.

110. If you need a class to manage a connection to a database that should only exist once throughout the application lifecycle, which OOP pattern is appropriate?

a) Prototype
b) Singleton
c) Facade
d) Adapter
Correct Answer: b) Singleton
Explanation:
Singleton ensures exactly one instance exists, which is ideal for shared resources like database connection pools.

111. Can you prevent a final class from being instantiated?

a) Yes, by making it abstract
b) Yes, by making its constructor private
c) No, final classes are forced to be instantiated
d) Yes, by removing all variables
Correct Answer: b) Yes, by making its constructor private
Explanation:
A final class cannot be extended, but its instantiation can still be prevented by declaring a private constructor (e.g., java.lang.Math).

112. Is string manipulation considered an OOP concept?

a) Yes, Strings are the root of OOP
b) No, it is a standard library feature, though Strings in Java are implemented as Objects
c) Yes, because Strings are primitives
d) No, Strings are not part of Java
Correct Answer: b) No, it is a standard library feature, though Strings in Java are implemented as Objects
Explanation:
String manipulation is part of Java's standard API logic, not a core theoretical principle of OOP like Inheritance or Polymorphism.

113. Which OOP concept is utilized when you call System.out.println() in Java?

a) Inheritance
b) Method Overloading
c) Object Cloning
d) Multiple Inheritance
Correct Answer: b) Method Overloading
Explanation:
The println() method is highly overloaded in the PrintStream class to accept int, double, String, Object, etc.

114. What is 'Coupling' in Java?

a) The process of joining two strings
b) The measure of how closely connected two routines or modules are
c) Compiling two classes together
d) Creating objects inside a loop
Correct Answer: b) The measure of how closely connected two routines or modules are
Explanation:
Coupling dictates inter-class dependencies. Good OOP design mandates loose coupling.

115. How do you achieve 100% loose coupling in Java?

a) Using abstract classes
b) Using interfaces and dependency injection
c) Using static methods exclusively
d) Using final variables
Correct Answer: b) Using interfaces and dependency injection
Explanation:
By programming to an interface rather than an implementation, components do not depend on exact classes, achieving loose coupling.

116. What is the primary difference between a class and an interface?

a) A class can have state (instance fields); a traditional interface cannot
b) An interface can be instantiated, a class cannot
c) A class can be implemented, an interface is extended
d) There is no difference
Correct Answer: a) A class can have state (instance fields); a traditional interface cannot
Explanation:
Classes hold both state (variables) and behavior (methods), whereas interfaces traditionally define only behavior contracts (and constants).

117. What does a 'ClassCastException' signify?

a) A class file was corrupted
b) You attempted to cast an object to a subclass of which it is not an instance
c) The JVM failed to cast a primitive type
d) A class could not be loaded into memory
Correct Answer: b) You attempted to cast an object to a subclass of which it is not an instance
Explanation:
This runtime exception occurs when trying to cast an object reference to a type that is incompatible with the actual runtime object.

118. What type of inheritance does Java use for classes to avoid complexity?

a) Multiple Inheritance
b) Single Inheritance
c) Hybrid Inheritance
d) Tree Inheritance
Correct Answer: b) Single Inheritance
Explanation:
Java classes support single inheritance (one direct parent) to prevent ambiguity (diamond problem).

119. In terms of OOP, what does a 'package' do?

a) Compresses code to save disk space
b) Groups related classes and interfaces, providing namespace management and access control
c) Converts source code to machine code
d) Executes Java programs automatically
Correct Answer: b) Groups related classes and interfaces, providing namespace management and access control
Explanation:
Packages organize code logically, prevent naming collisions, and provide a boundary for package-private access modifiers.

120. Can a superclass reference variable hold a subclass object?

a) Yes, this is upcasting and forms the basis of polymorphism
b) No, types must match exactly
c) Yes, but only if the subclass is abstract
d) No, a compile error will occur
Correct Answer: a) Yes, this is upcasting and forms the basis of polymorphism
Explanation:
Parent p = new Child(); is completely valid because a Child IS-A Parent. It enables writing flexible, reusable code.

121. Can a subclass reference variable hold a superclass object?

a) Yes, implicitly
b) No, it requires explicit downcasting, and will fail at runtime if the object isn't actually a subclass instance
c) Yes, but only using interfaces
d) No, it is strictly forbidden by the compiler in all cases
Correct Answer: b) No, it requires explicit downcasting, and will fail at runtime if the object isn't actually a subclass instance
Explanation:
Child c = new Parent(); causes a compile error. Child c = (Child) new Parent(); compiles but throws ClassCastException at runtime.

122. What is the 'Object' class method used to test if two objects are meaningfully equal?

a) compare()
b) ==
c) equals(Object obj)
d) isEqual()
Correct Answer: c) equals(Object obj)
Explanation:
The equals() method is provided by the Object class and is intended to be overridden to compare the state of two objects logically.

123. What is the difference between '==' and the 'equals()' method in Java?

a) They do exactly the same thing
b) '==' checks memory reference equality, whereas 'equals()' is meant to check logical value equality
c) '==' checks logical value equality, whereas 'equals()' checks memory references
d) There is no '==' operator for objects
Correct Answer: b) '==' checks memory reference equality, whereas 'equals()' is meant to check logical value equality
Explanation:
'==' verifies if two references point to the exact same memory location. equals() checks if the data inside the objects is equivalent (if overridden).

124. What method is recommended to be overridden whenever you override 'equals()'?

a) toString()
b) finalize()
c) hashCode()
d) clone()
Correct Answer: c) hashCode()
Explanation:
The Java contract requires that if two objects are equal according to equals(), they must have the same hashCode to function properly in Hash-based collections.

125. Which Object class method returns a string representation of the object?

a) stringValue()
b) toString()
c) print()
d) asString()
Correct Answer: b) toString()
Explanation:
The toString() method is implicitly called when an object is printed or concatenated with a string.
← Previous: Latest Java Loops MCQs
Java Operators MCQs

Java Operators MCQs

Java operators are special symbols and keywords used to perform operations on variables and values, governing arithmetic calculations, logical evaluations,…

By MCQs Generator
Latest Java Arrays MCQs

Latest Java Arrays MCQs

In Java, an array is a dynamically allocated object used to store a fixed-size sequential collection of elements of the…

By MCQs Generator
Latest Java Generics MCQs

Latest Java Generics MCQs

Java generics introduce compile-time type safety and reusability by allowing classes, interfaces, and methods to operate on parameterized types. Introduced…

By MCQs Generator