Object-Oriented Concepts in Core Java | Advanced OOP in Java: MCQs for Mastery
Dive into essential concepts of Object-Oriented Programming (OOP) in Core Java. This set of 30 MCQs is crafted for Java enthusiasts aiming to strengthen their knowledge of classes, objects, constructors, static blocks, method overriding, method overloading, and encapsulation in Java. Enhance your understanding of advanced OOP principles and become proficient in applying Java access modifiers.
MCQs
1-10: Deep Dive into Classes and Objects
Which of the following is true about a class in Java?
A) A blueprint for objects
B) It contains only static methods
C) It represents a single instance
D) None of the above
In Java, an object is an instance of:
A) A variable
B) A class
C) A method
D) A primitive data type
Which statement about classes and objects is incorrect?
A) Classes can contain fields and methods
B) Objects can directly hold multiple instances of classes
C) An object is created from a class
D) A class can have multiple instances
How can we access members of an object in Java?
A) Using the class name
B) Using the object reference
C) Using static access
D) None of the above
The keyword new in Java is used for:
A) Declaring a new class
B) Creating an instance of a class
C) Creating a new method
D) Initializing a variable
In Java, which of the following keywords is used to create an instance of a class?
A) init
B) this
C) new
D) create
Which of the following is not a characteristic of an object?
A) State
B) Behavior
C) Identification
D) Abstraction
What does this keyword represent within a class?
A) Current object instance
B) Parent class
C) Child class
D) None of the above
Objects in Java are stored in:
A) Stack memory
B) Heap memory
C) Register memory
D) Class memory
A constructor is primarily used to:
A) Define the structure of the class
B) Instantiate objects of the class
C) Access object variables
D) Destroy objects
11-15: Constructors and Static Blocks
What is the role of a constructor in Java?
A) To initialize a class
B) To initialize an object
C) To define method behavior
D) To terminate a class
Which of the following statements about static blocks is correct?
A) They execute only once
B) They execute every time a method is called
C) They can access non-static variables
D) They are called explicitly
What is a default constructor?
A) A constructor defined by the programmer
B) A no-argument constructor provided by Java if none is specified
C) A constructor with parameters
D) None of the above
When does a static block execute in Java?
A) When the program ends
B) During object creation
C) When the class is loaded
D) None of the above
How many times can a static block run per class?
A) As many times as there are objects
B) Only once, when the class is loaded
C) Twice for each method call
D) Every time a variable is used
16-20: Method Overriding and Overloading
Which of the following methods can be overridden?
A) Static methods
B) Instance methods
C) Private methods
D) Final methods
Method overloading is achieved by:
A) Changing method name
B) Changing the parameter list
C) Changing return type
D) Using the final keyword
Which of the following is a valid example of method overriding?
A) public void display()
B) static void show()
C) private void set()
D) public final void get()
Can two methods have the same name if they differ only by return type?
A) Yes
B) No
C) Only in certain cases
D) Depends on visibility
Which keyword is used to access a superclass method when overriding?
A) this
B) base
C) super
D) parent
21-25: Access Modifiers and Encapsulation
Which access modifier allows a method to be accessible within the same package but not from outside?
A) public
B) private
C) protected
D) default (no modifier)
A private variable in a class can be accessed:
A) Directly from another class
B) Only through getter and setter methods
C) By using the protected keyword
D) Using this keyword
Which of the following best defines encapsulation?
A) Hiding the implementation details from the user
B) Using the same method name with different parameters
C) Accessing fields directly
D) Inheriting from another class
What is the benefit of using encapsulation in Java?
A) To allow unrestricted access to fields
B) To control object properties and restrict data manipulation
C) To override static methods
D) None of the above
Encapsulation can be implemented in Java using:
A) Constructors only
B) Private variables and public methods
C) Static blocks
D) Public fields only
26-30: Miscellaneous Advanced OOP Concepts
Can a Java class have more than one static block?
A) Yes, and they will run sequentially
B) No, only one is allowed
C) Yes, but only one will execute
D) None of the above
Which access modifier can be used to make a variable accessible across all classes in Java?
A) protected
B) private
C) public
D) default
If a method in the superclass is marked as final, then:
A) It cannot be overridden
B) It can be overridden
C) It must be overloaded
D) It becomes abstract
What is an advantage of method overloading in Java?
A) It enhances code readability
B) It forces object inheritance
C) It reduces memory usage
D) It allows cross-package access
Which keyword prevents a class from being extended?
A) static
B) abstract
C) final
D) synchronized
Answer Key
Qno
Answer
1
A) A blueprint for objects
2
B) A class
3
B) Objects can directly hold multiple instances of classes
4
B) Using the object reference
5
B) Creating an instance of a class
6
C) new
7
D) Abstraction
8
A) Current object instance
9
B) Heap memory
10
B) Instantiate objects of the class
11
B) To initialize an object
12
A) They execute only once
13
B) A no-argument constructor provided by Java if none is specified
14
C) When the class is loaded
15
B) Only once, when the class is loaded
16
B) Instance methods
17
B) Changing the parameter list
18
A) public void display()
19
B) No
20
C) super
21
D) default (no modifier)
22
B) Only through getter and setter methods
23
A) Hiding the implementation details from the user
24
B) To control object properties and restrict data manipulation