2. Object-Oriented Questions Flashcards

1
Q

What is polymorphism? Give an example.

A

It’s when classes have different functionality while sharing the same interface.

For example, you can have an Employee class, a Contractor class that inherits from Employee, and a PermanentEmployee class that also inherits from Employee. If the Employee class has a method called CalculateSalary, the Contractor and the PermanentEmployee classes could have two entirely different implementations of it. Meaning that even though they share the same interface, the behaviour of the objects changes.

Method overloads are also a form of polymorphism.

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

What is encapsulation and abstraction?

A

Encapsulation prevents access to implementation details whereas abstraction allows making relevant information visible. In fact, abstractions are usually implemented as abstract classes or interfaces.

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

What is inheritance?

A

It’s when a class is based on another class, taking on its characteristics.

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

Can a class inherit multiple classes?

A

No. However, it can implement multiple interfaces.

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

What are the four pillars of OOP?

A
  1. Abstraction
  2. Polymorphism
  3. Inheritance
  4. Encapsulation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly