Object Oriented Programming - class, object, encapsulation, inheritance, polymorphism, abstract classes - One Line Questions
1.
What is an abstract class in OOP? —
A class that cannot be instantiated and may contain abstract methods.
2.
A class that cannot be instantiated and is designed to be inherited from is typically: —
An abstract class
3.
What is a constructor in the context of a class? —
A special method called automatically when an object is created.
4.
What happens when you create an object from a class? —
Memory is allocated for the object's data.
5.
Which of the following best describes the concept of a 'class'? —
A user-defined data type that defines properties and behaviors.
6.
A class that contains only abstract methods and no concrete methods or instance variables is often called an: —
Interface
7.
Which OOP concept promotes code reuse by allowing classes to share common functionality? —
Inheritance
8.
What is the fundamental difference between an abstract class and an interface in many OOP languages? —
An abstract class can have instance variables, while an interface cannot.
9.
What is the relationship between a class and an object? —
A class is a blueprint, and an object is an instance of that blueprint.
10.
What are the actions or functions that an object can perform called? —
Methods
11.
A class that inherits from another class is called a: —
Derived class
12.
What is an instance of a class called in OOP? —
Object
13.
What is the primary benefit of encapsulation? —
Data hiding and modularity
14.
Which type of polymorphism allows a derived class to provide a specific implementation of a method that is already defined in its base class? —
Runtime Polymorphism (Overriding)
15.
The process of an object taking on the properties of another object is known as: —
Inheritance
16.
What is the term for a method defined in an abstract class that has no implementation? —
Abstract method
17.
A class from which other classes inherit is called a: —
Base class
18.
In OOP, inheritance allows a class to reuse code from another class. This promotes: —
Reusability
19.
In OOP, what concept allows a new class to derive properties and behaviors from an existing class? —
Inheritance
20.
Which OOP concept focuses on showing only essential features and hiding unnecessary details? —
Abstraction
21.
Consider a `Car` class inheriting from a `Vehicle` class. The `startEngine()` method is defined in `Vehicle` and overridden in `Car`. This is an example of: —
Runtime Polymorphism
22.
Which of the following is NOT a core principle of OOP? —
Proceduralism
23.
Which OOP concept is most related to the idea of 'is-a' relationship? —
Inheritance
24.
An abstract method is a method that: —
Is declared but not implemented in the abstract class.
25.
Polymorphism allows you to treat objects of different classes in a uniform way if they share a common: —
Base class or interface
26.
Which OOP principle involves bundling data (attributes) and methods (functions) that operate on the data within a single unit? —
27.
What is the term for the mechanism that restricts direct access to some of an object's components, often referred to as 'data hiding'? —
Encapsulation
28.
What OOP principle allows objects of different classes to respond to the same method call in their own specific ways? —
Polymorphism
29.
The ability of a function or method to perform different actions based on the object it is acting upon is called: —
Polymorphism
30.
Which OOP principle helps in reducing complexity by modeling real-world entities? —
Abstraction
31.
Which OOP principle allows a single interface to represent multiple underlying forms? —
Polymorphism
32.
What does it mean for a class to be 'instantiable'? —
Objects can be created from it.
33.
What is a key advantage of polymorphism? —
It simplifies the process of writing code for diverse object types.
34.
In OOP, what are the characteristics or properties of an object called? —
Attributes
35.
The concept of 'object-oriented programming' was first popularized by which company? —
Xerox
36.
Consider a `Dog` class and a `Cat` class, both inheriting from an `Animal` class. This is an example of: —
Hierarchical Inheritance
37.
If a class `A` inherits from class `B`, and class `B` inherits from class `C`, this is an example of: —
Multilevel Inheritance
38.
In Object-Oriented Programming (OOP), what is a blueprint or a template for creating objects called? —
Class
39.
An abstract class can contain: —
Both abstract and concrete methods.
40.
Encapsulation helps in making code more: —
Maintainable and secure
41.
A method signature includes the method name and its: —
Parameters
42.
If a class has multiple methods with the same name but different parameter lists, this is an example of: —
Compile-time Polymorphism
43.
Which type of polymorphism allows a method to have the same name but different parameters in the same class? —
Compile-time Polymorphism (Overloading)
44.
What keyword is typically used to define an abstract class in many OOP languages? —
abstract
45.
If a class `Shape` has a method `draw()`, and `Circle`, `Square`, `Triangle` classes inherit from `Shape` and override `draw()`, calling `draw()` on a `Shape` reference pointing to a `Circle` object will execute: —
The `draw()` method in the `Circle` class.
46.
What does the term 'object state' refer to in OOP? —
The values of the object's attributes at a particular point in time.
47.
What is the main purpose of using abstract classes? —
To enforce a common interface and structure for derived classes.
48.
What is the primary goal of abstraction in software design? —
To provide a high-level view while hiding implementation details.
49.
What is the primary purpose of data hiding in encapsulation? —
To protect the internal state of an object from unintended external modifications.
50.
What is a common way to achieve abstraction in OOP? —
Using abstract classes and interfaces.