OOP Flashcards

1
Q

What is method overriding?

A

An approach of defining multiple methods with the same name and with the same parameters. But different functionality

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is encapsulation?

A

Prevents access to implementation details. Also known as data hiding.
We can do this by declaring variables as private. And by making one pair or getters and setters methods or properties be private.

It refers to an object’s ability to hide data and behavior that are not necessary to its user. Ex: calculator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is inheritance?

A

The process of creating a new class from an existing class such that the new class acquires all the properties and behaviors of the existing class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the 4 basic concepts of OOP?

A

Abstraction
Encapsulation
Inheritance
Polymorphism

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is abstraction?

A

Displaying only the necessary details of the object to the users and hiding the unnecessary things.
Ex: a driver should know the name of the car, color, gear, break, steering, etc. However he doesn’t need to know Diesel engine, engine of the car, silencer etc.

it is used to hide the implementation details and display only essential features of the object.

In Abstraction, by using access modifiers, we can hide the required details of the object and expose only necessary methods and properties through an object’s reference.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is method hiding?

A

Hiding parent class methods from its subclasses. Using the ‘new’ keyword in the subclass method will not give you access to the parent class method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the difference between abstraction and encapsulation?

A

Encapsulation is the process of hiding irrelevant information from the user or used to protect the data.

Abstraction is showing the relevant information to the user.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is method overloading?

A

Same methods and different parameters.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Why do we override a method?

A
If the super class method logic is not fulfilling the sub-class requirements, then the subclass needs to override that method with the required logic.
Ex: a fish is an animal but may eat differently from other animals.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the 5 types of inheritance?

A
Single inheritance 
Hierarchical inheritance 
Multilevel inheritance 
Hybrid inheritance 
Multiple inheritance
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Why do we use inheritance?

A

Used for code reusability and changeability purpose. Changeability meaning overriding a feature or adding more functionality to the object.

Implementation inheritance is whenever a class is derived from another class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is polymorphism?

A

Means one thing having many forms. Behaving differently depending on the input received.

Implemented in 3 ways:
Method overriding
Method overloading
Method hiding

A person at the same time can have different characteristic. Like a man at the same time is a father, a husband, an employee

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

When should we overload a method?

A

If you want to execute the same logic but with different types of values.

Ex: adding two integers, two floats, two strings, then you need to define three method with the same name (Add) but enter different values for the parameters on each method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is object oriented programming? And it’s benefits?

A

object-oriented programming is about creating objects that contain both data and methods.

Its a concept that allows developers to organize entities and objects.

OOP is faster and easier to execute
OOP provides a clear structure for the programs
OOP helps to keep the C# code DRY “Don’t Repeat Yourself”, and makes the code easier to maintain, modify and debug
OOP makes it possible to create full reusable applications with less code and shorter development time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly