0% found this document useful (0 votes)
5 views15 pages

OOP Reviewer

This document is a multiple-choice reviewer focused on Object-Oriented Programming (OOP) concepts such as encapsulation, inheritance, and polymorphism. It includes 50 questions along with an answer key to reinforce understanding of OOP principles and Java basics. The questions cover a range of topics, including method overloading, access modifiers, and garbage collection.

Uploaded by

k.ursabia.543388
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)
5 views15 pages

OOP Reviewer

This document is a multiple-choice reviewer focused on Object-Oriented Programming (OOP) concepts such as encapsulation, inheritance, and polymorphism. It includes 50 questions along with an answer key to reinforce understanding of OOP principles and Java basics. The questions cover a range of topics, including method overloading, access modifiers, and garbage collection.

Uploaded by

k.ursabia.543388
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/ 15

Here’s a multiple-choice reviewer based on the provided content from the PDFs on Object-

Oriented Programming (OOP). This covers the key concepts of encapsulation, inheritance,
polymorphism, and more. At the end, I will also provide an answer key.

### Week 6 & 7 Reviewer: Object-Oriented Programming (OOP)

#### 1. Which of the following best describes **encapsulation** in Object-Oriented


Programming?

A. The ability of a class to derive properties and methods from another class.

B. The bundling of data with the methods that operate on that data.

C. The ability to define multiple methods with the same name but different signatures.

D. The process of calling the appropriate method based on the object type at runtime.

#### 2. What is **inheritance** in Object-Oriented Programming?

A. When an object takes many forms.

B. When a method is overridden in a subclass.

C. When a class acquires the properties and behaviors of another class.

D. When multiple classes have methods with the same name but different
implementations.

#### 3. **Polymorphism** allows:

A. A single action to behave differently based on the object that invokes it.

B. The use of methods that are private to the parent class.

C. The prevention of a class from being inherited.

D. The storing of key-value pairs in a Hashtable.

#### 4. Which of the following is an example of **static polymorphism**?


A. Overriding a method in a subclass.

B. Overloading methods with different parameters.

C. Using inheritance to access parent class properties.

D. Instantiating a new object from a class.

#### 5. In the context of Java, the keyword **`extends`** is used to:

A. Access private members of a class.

B. Inherit methods and properties from a superclass.

C. Create a method that cannot be overridden.

D. Store data in the form of key/value pairs.

#### 6. Which of the following principles is demonstrated by creating a subclass of a


superclass, where the subclass inherits methods from the superclass but overrides one of
them?

A. Encapsulation

B. Polymorphism

C. Inheritance

D. Overloading

#### 7. **Overriding** a method means:

A. Creating a new method with the same name but different parameters.

B. Changing the implementation of a method inherited from a superclass.

C. Adding new methods to a superclass.

D. Calling a method from a different class without creating an object.

#### 8. Which of the following statements about **encapsulation** is correct?


A. It allows the programmer to change the code inside a method without affecting other
classes.

B. It prevents any method from being overridden in a subclass.

C. It stops the class from inheriting methods from another class.

D. It requires that all methods within a class be public.

#### 9. In Object-Oriented Programming, a **constructor** is used to:

A. Inherit properties from a superclass.

B. Automatically initialize an object when it is created.

C. Access private data members of a class.

D. Set default values for static members of a class.

#### 10. **Abstraction** in Object-Oriented Programming:

A. Hides the implementation details and shows only essential information.

B. Restricts the visibility of certain members of a class.

C. Allows an object to take many forms.

D. Provides multiple ways to define a method with the same name.

### Answer Key:

1. B

2. C

3. A

4. B

5. B

6. B

7. B
8. A

9. B

10. A

This set of questions should help reinforce the core concepts of OOP discussed in your
lessons. Let me know if you'd like to adjust or add more questions!

#### 11. What is the difference between **overloading** and **overriding** in Java?

A. Overloading refers to multiple methods with the same name but different signatures,
while overriding refers to redefining a method in a subclass.

B. Overloading happens at runtime, while overriding happens at compile time.

C. Overloading occurs only with private methods, while overriding occurs with public
methods.

D. Overloading changes the return type of a method, while overriding changes its
parameters.

#### 12. **Static methods** in Java:

A. Can be called only from a non-static context.

B. Cannot access instance variables directly.

C. Can be overridden by a subclass.

D. Are inherited but cannot be accessed directly by the subclass.

#### 13. In the following code, what does the keyword **`this`** represent?

```java

class Car {

private String color;

Car(String color) {

this.color = color;
}

```

A. It refers to the current instance of the Car class.

B. It refers to the superclass of the Car class.

C. It refers to the constructor of the Car class.

D. It refers to the static methods in the Car class.

#### 14. **Access modifiers** in Java include:

A. Public, Private, Protected, and Final

B. Public, Private, Protected, and Static

C. Public, Private, Protected, and Default

D. Public, Final, Abstract, and Static

#### 15. The **protected** access modifier:

A. Makes a method accessible only within the class it is declared.

B. Makes a method accessible to subclasses and classes in the same package.

C. Makes a method accessible only within the same package.

D. Makes a method accessible only to the class and its objects.

#### 16. Which of the following is **true** about **abstract classes**?

A. Abstract classes cannot have concrete (non-abstract) methods.

B. An abstract class cannot be instantiated.

C. An abstract class must have at least one abstract method.

D. An abstract class can only be used if it is final.


#### 17. **Interfaces** in Java:

A. Can contain default and static methods starting from Java 8.

B. Can have instance variables.

C. Allow multiple inheritance of methods and instance variables.

D. Must contain only abstract methods.

#### 18. The main difference between **abstract classes** and **interfaces** is:

A. Abstract classes support multiple inheritance, while interfaces do not.

B. Interfaces provide method implementation, while abstract classes do not.

C. Interfaces cannot have static methods, while abstract classes can.

D. Abstract classes can have both concrete and abstract methods, while interfaces can
only have abstract methods.

#### 19. Which of the following demonstrates **dynamic polymorphism**?

A. A method in a class being overloaded with different signatures.

B. A subclass overriding a method from a superclass.

C. Calling a static method from a superclass.

D. Using different constructors to initialize objects.

#### 20. The **`super`** keyword in Java is used to:

A. Call a method in the current class.

B. Access a method from the subclass.

C. Access a member from the superclass.

D. Declare a method as abstract.

#### 21. In Java, an **inner class** is:


A. A class that is declared inside a method.

B. A class that is declared inside another class.

C. A class that is declared as abstract.

D. A class that extends another class.

#### 22. **Final methods** in Java:

A. Can be overridden by subclasses.

B. Cannot be overridden by subclasses.

C. Can be called only within the class they are declared.

D. Can be accessed only by the class and its objects.

#### 23. The **default** access modifier in Java:

A. Makes a method accessible from anywhere in the project.

B. Restricts access to the same class only.

C. Allows access within the same package.

D. Restricts access to the same package and subclasses only.

#### 24. Which of the following is an example of **multiple inheritance** in Java?

A. A class inheriting from multiple classes using the `extends` keyword.

B. A class implementing multiple interfaces.

C. A class inheriting from a class and an interface simultaneously.

D. A class extending two abstract classes.

#### 25. **Constructor overloading** means:

A. Defining multiple constructors with different parameter lists in the same class.

B. Overriding the constructor in a subclass.


C. Using `super` to call the constructor of the superclass.

D. Having multiple constructors with different return types.

#### 26. Which of the following is **NOT** a principle of OOP?

A. Encapsulation

B. Inheritance

C. Polymorphism

D. Compilation

#### 27. In Java, **method overloading**:

A. Allows multiple methods with the same name but different parameters.

B. Allows methods to return multiple values.

C. Allows multiple methods with different return types but the same name.

D. Allows methods to access variables from other classes.

#### 28. **Aggregation** in OOP refers to:

A. A "has-a" relationship between two classes.

B. A "uses-a" relationship between two classes.

C. A "is-a" relationship between two classes.

D. A relationship where one class inherits from another.

#### 29. In **composition**, the lifetime of the contained object:

A. Is independent of the container object.

B. Is dependent on the container object.

C. Lasts until the container object is destroyed.

D. Cannot be controlled by the programmer.


#### 30. **Method overriding** is used to:

A. Allow two methods to share the same name but different parameters.

B. Provide a new implementation of a method inherited from a superclass.

C. Call a method from another class.

D. Create a constructor in a subclass that overrides the constructor in the superclass.

#### 31. A **singleton** class in Java:

A. Allows only one instance of the class to be created.

B. Cannot have a constructor.

C. Allows multiple instances of the class but restricts access to one method.

D. Is a final class that cannot be inherited.

#### 32. Which of the following statements about **abstract methods** is true?

A. Abstract methods can be private.

B. Abstract methods can have a body.

C. Abstract methods must be implemented by subclasses.

D. Abstract methods can only be declared in interfaces.

#### 33. **Private** methods:

A. Can be accessed directly from other classes.

B. Can only be accessed within the same class.

C. Can be overridden in a subclass.

D. Can only be accessed by subclasses.

#### 34. In Java, **instance variables** are:


A. Variables defined inside a method.

B. Variables that are shared across all instances of a class.

C. Variables defined within a class but outside any method.

D. Variables that can only be accessed by the static methods.

#### 35. Which of the following is true about **static variables** in Java?

A. Static variables can only be declared in abstract classes.

B. Static variables are shared by all instances of a class.

C. Static variables cannot be initialized during declaration.

D. Static variables can only be accessed within the class they are declared in.

#### 36. **Interfaces** in Java:

A. Can contain fields.

B. Allow you to define constructors.

C. Can contain default methods from Java 8 onwards.

D. Can implement other interfaces.

#### 37. **Multiple inheritance** is:

A. Not allowed in Java with classes but allowed with interfaces.

B. Allowed only through abstract classes.

C. Allowed only with classes that implement interfaces.

D. Not supported in Java in any form.

#### 38. **Garbage collection** in Java:

A. Frees up memory by manually deleting unused objects.

B. Is used to allocate memory to new objects.


C. Automatically removes objects that are no longer referenced.

D. Can be controlled by the programmer directly.

#### 39. In Java, **a class can inherit**:

A. Only from one superclass.

B. From multiple classes.

C. From multiple interfaces and classes.

D. From abstract classes only.

#### 40. **UML (Unified Modeling Language)** is:

A. A programming language used to define class structures.

B. A graphical notation for designing object-oriented software.

C. A method of declaring variables in a class.

D. A Java-specific tool used for creating class diagrams.

#### 41. Which of the following is true for **final variables** in Java?

A. They can be modified only by the class in which they are declared.

B. They can be changed once initialized.

C. They can be initialized later but only once.

D. They cannot be used in static methods.

#### 42. The **main method** in Java must:

A. Be declared as static.

B. Return an integer.

C. Be declared as abstract.

D. Be overloaded.
#### 43. **Packages** in Java are used to:

A. Override methods in a superclass.

B. Access private members of another class.

C. Organize classes and interfaces into namespaces

D. Allow multiple inheritance.

#### 44. **Nested classes** in Java:

A. Cannot be instantiated directly.

B. Can access the private members of the outer class.

C. Must be static.

D. Cannot inherit from other classes.

#### 45. In Java, **anonymous classes** are:

A. Classes with no constructor.

B. Inner classes with no name.

C. Final classes that cannot be inherited.

D. Interfaces that contain only abstract methods.

#### 46. **Enums** in Java:

A. Are used to define a set of named constants.

B. Are equivalent to integer values.

C. Can only be used inside interfaces.

D. Cannot have methods or constructors.


#### 47. A **try-catch block** in Java is used for:

A. Handling compile-time errors.

B. Defining abstract methods.

C. Handling exceptions at runtime.

D. Defining constructors.

#### 48. The **`toString`** method in Java:

A. Converts an integer to a string.

B. Is used to return a string representation of an object.

C. Must be declared as abstract.

D. Is a method that cannot be overridden.

#### 49. **Reflection** in Java is used for:

A. Creating new objects at runtime.

B. Modifying private fields of an object at runtime.

C. Loading new classes dynamically and inspecting their structure.

D. Calling private methods from other classes.

#### 50. **Default constructors** in Java:

A. Are automatically generated if no other constructors are defined.

B. Must be explicitly declared in every class.

C. Can be overridden by subclasses.

D. Must take at least one parameter.

---
### Updated Answer Key:

11. A

12. B

13. A

14. C

15. B

16. B

17. A

18. D

19. B

20. C

21. B

22. B

23. C

24. B

25. A

26. D

27. A

28. A

29. B

30. B

31. A

32. C

33. B

34. C
35. B

36. C

37. A

38. C

39. A

40. B

41. C

42. A

43. C

44. B

45. B

46. A

47. C

48. B

49. C

50. A

This full set of 50 questions should provide comprehensive coverage of Object-Oriented


Programming principles and Java basics. Let me know if you'd like further adjustments or
additional questions!

You might also like