Object Oriented Programming (OOP) Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Define object.

A

An object is an instance of a class.

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

What is the need for self in classes?

A

self is used to reference the current instance of a class. It is used to access the attributes and methods of the class within its own definition.

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

Define attribute.

A

An attribute is a characteristic of an entity or object.

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

What is inheritance?

A

Inheritance is the retrieval of all the methods and attributes from a super class, so they can be used within a sub-class.

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

What is encapsulation?

A

Encapsulation is the bundling of attributes and methods together within a class. The attributes should only be accessed and modified by the classs own methods.

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

What is OOP?

A

OOP stands for Object-Oriented Programming. It is a way of coding that involves classes, objects, and methods.

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

Define method.

A

A method is an implementation of behavior inside a class.

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

What are static methods?

A

Static methods are methods that dont require instantiation or self. They can be relevant to the class, but may not require any of the attributes in the constructor method.

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

What is instantiation?

A

Instantiation is the process of creating a new instance of a class or an object.

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

What is an access modifier?

A

An access modifier is used in object-oriented programming to control the visibility of class attributes and methods. There are three types: public, protected, and private.

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

What is encapsulation?

A

Encapsulation is the bundling of attributes and methods together within a class, where a classs attributes should only be accessed and modified by its own methods (getters and setters). It ensures code security and efficiency.

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

What is the mantra of object-oriented programming?

A

The mantra of object-oriented programming is to favor composition over inheritance, program to interfaces rather than implementations, and ensure code security and usability for users.

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

What are getters and setters?

A

Getters are simple return statements used to retrieve attributes. Setters usually take in parameters and are used to modify attributes. They can also include validation.

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

Why should you encapsulate what varies?

A

Encapsulating what varies ensures that the code is accurate and representative of the desired blueprint. It also improves code security and efficiency. If something can change in any circumstance, it needs to be encapsulated to prevent potential issues.

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

What is overriding?

A

Overriding is where you have a method in the superclass and want it to behave differently in the subclass. It is a form of polymorphism.

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

Define class.

A

A class is a custom data type that acts as a blueprint for creating objects, attributes, and methods.

17
Q

What is aggregation?

A

Aggregation is passing in a whole object outside of a class. Uses-a relationship, where objects can exist separately.

18
Q

What is composition?

A

Composition is creating an instance of the main class within the other class, and assigning it to an object. It represents an intrinsic link or has-a relationship. Objects cannot exist separately

19
Q

What is polymorphism?

A

Polymorphism is the ability of a method to exhibit different behavior depending on the object on which the method is invoked.

20
Q

Why is composition favored over inheritance?

A

Composition is favored over inheritance because inheritance can lead to redundancy and poor memory usage. Inheritance inherits all the data even if its not needed, while composition allows for more efficient and secure code. Additionally, composition does not break encapsulation.