Object Oriented Programming (OOP) MCQs

Object Oriented Programming (OOP) MCQs

These Object Oriented Programming (OOP) multiple-choice questions and their answers will help you strengthen your grip on the subject of Object Oriented Programming (OOP). You can prepare for an upcoming exam or job interview with these 90+ Object Oriented Programming (OOP) MCQs.
So scroll down and start answering.

1: The class used as a basis for inheritance is the ____ class.

A.   Base

B.   Child

C.   Derived

D.   Extends

2: Multiple inheritance is when a ________ class has ________ base classes.

A.   Derived, two or more

B.   Base; two or more

C.   Derived; one

D.   Base; one

A.   Composition

B.   Extension

C.   Is-a

D.   Scope

4: The ________ class constructor is called before the ________ class constructor.

A.   Base, derived

B.   Derived, derived

C.   Derived, base

D.   Base, base

5: Protected members of a base class are like ________, but they may be accessed by derived classes.

A.   Private members

B.   Base class members

C.   Public members

D.   All of the above

6: ________ members of a base class are never accessible to a derived class.

A.   Public

B.   Private

C.   Protected

D.   All of the above

7: By convention, a class diagram contains the ____ following each attribute or method.

A.   Data type

B.   Data field

C.   Argument

D.   Class

8: Class ________ represents an image that can be displayed on a jlabel.

A.   ImageIcon

B.   Icon

C.   ImageLabel

D.   None of the above

9: A ____ method is also known as a help method.

A.   Work

B.   Public

C.   Private

D.   Set

10: In oop, you declare a class that extends another class. this is called ________.

A.   Inheritance

B.   Encapsulation

C.   An Object

D.   Raw type

11: In a sequence diagram, the _____ indicates when an object sends or receives a message.

A.   Command line

B.   Focus

C.   Request link

D.   Lifeline

12: A class and its members can be described graphically using a notation known as the ____ notation.

A.   OON

B.   OOD

C.   UML

D.   OOP

13: A(n) ____ is a variable that is used within a function.

A.   Method

B.   Property

C.   Parameter

D.   Operator

14: What is an example of dynamic binding?

A.   Any method

B.   Method overloading

C.   Method overriding

D.   Compiling

15: For which case would the use of a static attribute be appropriate?

A.   The number of people in each house in a small neighborhood

B.   The lot size for each house in a small neighborhood

C.   The color of each house in a small neighborhood

D.   The weather conditions for each house in a small neighborhood

16: Why would you create an abstract class, if it can have no real instances?

A.   To avoid redundant coding in children

B.   To explore a hypothetical class

C.   To prevent unwanted method implementation

D.   To reserve memory for an unspecified class type

17: When does static binding happen?

A.   Only when you export

B.   Both at compile time and runtime

C.   At compile time

D.   At runtime

18: What is the best reason to use a design pattern?

A.   It will result in code that is more extensible and maintainable

B.   It will result in a more compact product.

C.   It will speed initial development.

D.   It will allow you to add that design pattern to your resume.

19: What is encapsulation?

A.   Defining classes by focusing on what is important for a purpose

B.   Hiding the data and implementation details within a class

C.   Making all methods private

D.   Using words to define classes

20: What is an IS-A relationship?

A.   It implies encapsulation.

B.   A superclass object has an IS-A relationship with its subclass.

C.   It implies a virtual method.

D.   A subclass object has an IS-A relationship with its superclass or interface

21: Ou want a method with behavior similar to a virtual method--it is meant to be overridden --expect that it does not have a method body. It just has a method signature. What kind of method should you use?

A.   An abstract method

B.   A public internal method

C.   An internal method

D.   A protected internal method

22: Which code creates a new object from the Employee class?

A.   Employee currentEmployee = Employee.Create();

B.   Employee currentEmployee = new Employee();

C.   Employee currentEmployee;

D.   Employee currentEmployee = Employee.New();

23: Which type of constructor cannot have a return type?

A.   Default

B.   Copy

C.   Parameterized

D.   Constructors do not have a return type

24: When is a constructor executed?

A.   When an object is created from a class using the new keyword

B.   When an class is defined using the class keyword

C.   Every time an object is referenced

D.   When an object is created from a class using the create keyword

25: F a local class is defined in a function, what is true for an object of that class?

A.   The object can be accessed, declared, and used locally in that function.

B.   The object must be declared inside any other function.

C.   The object is temporarily accessible outside the function.

D.   The object can call all the other class members anywhere in the program.

26: Which two blocks are used to handle and check errors?

A.   Do and check

B.   Catching and trying

C.   Try and catch

D.   Do and while

27: Why would you implement composition using an id instead of a reference?

A.   It makes it easier to save the entity.

B.   All of these answers

C.   It can make the entity retrieval more efficient

D.   It minimizes coupling.

28: Which statement best describes the method of inheritance in OOP?

A.   Inheritance describes the ability to create new classes based on an existing class.

B.   Inheritance means that a group of related properties, methods, and other members are treated as a single unit or object.

C.   Inheritance forces a class to have a single responsibility from only one parent.

D.   Inheritance means that you will never have multiple classes that can be used interchangeably, even though each class implements the same properties or methods in different ways.

29: Which type of inheritance ,when done continuously, is similar to a tree structure?

A.   Multilevel

B.   Hierarchical and multiple

C.   Hierarchical

D.   Multiple

30: Which statement is true?

A.   A default parameter's constructor is not equivalent to the default constructor

B.   A default constructor is inherited from a parent class

C.   A default constructor can be called explicitly

D.   A default constructor cannot be defined by the coder

31: Which of the following is NOT an advantage of using getters and setters?

A.   Getters and setters can speed up compilation.

B.   Getters and setters provide encapsulation of behavior.

C.   Getters and setters provide a debugging point for when a property changes at runtime.

D.   Getters and setters permit different access levels.

32: In context of OOP, what is association?

A.   Association is a relationship where all objects have their own life cycle and there is no owner.

B.   Association is the process where model elements cooperate to provide higher-level behavior.

C.   Association is whole/part relationship where one object is composed of one or more other objects, each of which is considered a part of the whole.

D.   Association is where all objects have their own life cycle, but there is ownerhip, and child objects can not belong to another parent object.

33: How are user stories different from use cases?

A.   User Stories are shorter and less detailed.

B.   User stories are more accurate.

C.   User stories are more detailed and structured.

D.   User storised are more anecdotal and personal.

34: Which type of inheritance must be used so that the resultant is hybrid?

A.   Multiple

B.   Any type of inheritance

C.   Multilevel

D.   Hierarchical

35: A language that does not support polymorphism but supports classes is considered what?

A.   An object-based language

B.   A class-based language

C.   A procedure-oriented language

D.   If classes are supported, polymorphism will be supported

36: Two classes combine private data members and provide public member functions to access and manipulate those data members. Where is abstraction used?

A.   Abstraction is using a private access specifier for the data members.

B.   Abstraction is using public member functions to access and manipulate the data members.

C.   Abstraction is using the class concept with both data members and member functions.

D.   There is insufficient information to decide where abstraction is being used.

37: What are the five Creational Design patterns by the Gang of Four ?

A.   Observer, State, Strategy, Template Method, and Visitor.

B.   Composite, Visitor, State, Prototype, and Singleton.

C.   Composite, Builder, Factory Method, Prototype, and Singleton.

D.   Abstract Factory, Builder, Factory Method, Prototype, and Singleton.

38: In multilevel inheritance, one class inherits how many classes?

A.   One class only

B.   Two classes

C.   As many classes as required

D.   At least two classes

39: If an object is passed by reference, the changes made in the function are reflected _.

A.   To the main object of the caller function, too

B.   On the caller function object and also the called function object

C.   On the copy of the object that is made during the pass

D.   Only in the local scope of the called function

40: What is a method?

A.   A set of instructions designed to perform a frequently used operation within a program and return no values

B.   The exact same thing as a function and subroutine

C.   A set of variables that can change over time

D.   A procedure associated with data and behaviour

41: A mobile phone is made up of components such as a motherboard, camera, and sensors. The motherboard represents all the functions of a phone, the display shows the display only, and the phone is represented as a whole. Which of the following has the highest level of abstraction?

A.   Camera

B.   Display

C.   Motherboard

D.   Mobile phone

42: Which class has the highest degree of abstraction in a multilevel inheritance relationship of five levels?

A.   The class at the third level

B.   The class at the first level

C.   All have the same degree of abstraction.

D.   The class at the second level

43: Which is NOT one of the basic types of inheritance?

A.   Multilevel inheritance

B.   Double inheritance

C.   Single inheritance

D.   Hierarchical inheritance

44: Why is code duplication so insidious?

A.   The duplication uses unnecessary space.

B.   One has to maintain all the duplicates.

C.   Duplication can cause intellectual property concerns.

D.   Duplication is easy to hide.

45: When and how often is a static constructor called?

A.   It is called initially when an object is created and called with every new object instance.

B.   It is called when an object is destroyed and only one time.

C.   It is called initially when an object is created and only one time.

D.   It is created at time when the object is discarded.

46: What is the purpose of static constructor?

A.   To initialize all the members with static value

B.   To delete the static members when not required

C.   To initialize the static members of class

D.   To clear all the static members' initialized values

47: What are CRC Cards?

A.   Code Responsibility Collection cards are a brainstorming tool used in the design of procedural software

B.   Class Responsibility collaboration cards are a brainstorming tool used in the design of oop software

C.   Code Responsibility Correction cards are tools used for debugging

D.   Code Responsibility Correction cards are tools for modeling

48: How are contents of a composition different from those of aggregation?

A.   If one element of an aggregation is dereferenced, all its elements are eligible for garbage collection

B.   If a composition dies, the contents die

C.   The contents of a composition are all siblings

D.   An aggregation contains only abstract classes

49: Which statement about compositions and aggregations is true?

A.   If one element of an aggregation is dereferenced, all its elements are eligible for garbage collection

B.   If a composition dies, the contents die

C.   The contents of a composition are all siblings

D.   An aggregation contains only abstract classes

50: What is the result of using more abstraction?

A.   It can increase code vulnerability

B.   It can make code unsafe

C.   It can limit code readability

D.   It can be safer for coding