Principles of programming Flashcards

(44 cards)

1
Q

What is a class in OOP?

A

A blueprint or definition of an object that defines attributes and methods.

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

What is an object?

A

An instance of a class with specific attribute values and behaviors.

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

What is instantiation?

A

The process of creating an object from a class definition.

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

What is a constructor?

A

A special method called when an object is instantiated to initialize attributes.

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

What are attributes?

A

Variables that hold data about the object.

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

What are methods?

A

Procedures or functions that define the behavior of an object.

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

What is encapsulation?

A

The bundling of data (attributes) and methods that operate on the data within a class, protecting it from outside access.

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

What are getters and setters?

A

Methods used to access (get) and modify (set) the values of private attributes.

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

What does it mean to make an attribute private?

A

The attribute is hidden from outside access and can only be accessed through methods inside the class.

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

What are access modifiers?

A

Keywords that control the visibility of class members, typically public, private, and protected.

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

What is polymorphism?

A

The ability of methods to behave differently based on the object they are called on, often achieved through method overriding.

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

What is inheritance?

A

A mechanism where a child class inherits attributes and methods from a parent class.

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

What is method overriding?

A

When a subclass provides a specific implementation of a method already defined in its parent class.

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

How is inheritance represented in UML?

A

With hollow-headed arrows pointing upward from the child class to the parent class.

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

What does ‘protected’ mean in OOP?

A

Attributes or methods accessible within their class and subclasses, but not from outside.

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

Why use encapsulation?

A

To protect data integrity by preventing direct access and modification of attributes.

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

What is meant by ‘message passing’ in OOP?

A

Objects communicate by calling each other’s public methods.

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

What is the difference between a superclass and a subclass?

A

Superclass is the parent class; subclass is the child class that inherits from the parent.

19
Q

What is ‘composition over inheritance’?

A

A design principle that favors building classes by combining simpler, stand-alone classes rather than deep inheritance hierarchies.

20
Q

What is the significance of using prewritten classes?

A

They promote code reuse and simplify system development.

21
Q

Why might OOP lead to more complex systems?

A

Because of extensive message passing and the creation of many interacting objects.

22
Q

What are some disadvantages of inheritance?

A

It can cause unintended behavior and tight coupling between classes.

23
Q

How do public and private methods differ?

A

Public methods are accessible outside the class; private methods are only used within the class.

24
Q

What is a UML class diagram?

A

A visual representation of a class showing its name, attributes, and methods.

25
What is the advantage of classes being self-contained?
They can be reused in different applications without dependency on other parts of the system.
26
What is the 'Separation of Concerns' principle?
Designing classes to focus on specific tasks, making systems easier to understand and maintain.
27
What is method signature?
The name and parameters of a method used to identify it uniquely.
28
What is meant by 'polymorphism allows an object to know the right method to use'?
At runtime, the correct overridden method is called based on the object's actual class.
29
Why might objects use more memory in OOP?
Because each object stores its own data and methods, leading to larger memory use compared to procedural code.
30
What are the benefits of modularity in classes?
Classes are easier to maintain, update, and reuse due to their isolated design.
31
What is an attribute?
A variable that holds data describing the object, such as 'number of masts' in a boat.
32
What is a getter?
A public method used to access the value of a private attribute.
33
What is a setter?
A public method used to modify the value of a private attribute.
34
What does overriding a method mean?
Changing the implementation of an inherited method to suit the subclass.
35
Why might you use the SUPER keyword in a constructor?
To call the parent class constructor and avoid duplicating initialization code.
36
What is the difference between private and protected attributes?
Private attributes are only accessible within the class; protected can also be accessed by subclasses.
37
How do objects interact in OOP?
By passing messages, i.e., calling each other's public methods.
38
What is a subclass?
A class that inherits from another class, also known as a child or derived class.
39
What is a superclass?
A class from which other classes inherit, also known as a parent or base class.
40
What is method signature repetition in overriding?
Repeating the method name and parameters in a subclass to override it.
41
How does polymorphism benefit a system?
It allows different objects to respond to the same method call in ways appropriate to their class.
42
Why is it important for classes to be self-contained?
So they can be reused and maintained independently without affecting other parts.
43
What is the risk of tightly coupling classes through inheritance?
Changes in a base class can unintentionally affect all derived classes.
44
What is composition in OOP?
Building complex classes by combining simpler objects rather than using inheritance.