OOP questions Flashcards

1
Q

Advantages of OOP

A
  • Can modify and maintain existing code more easily.
  • Reuse of code in other programs through libraries
  • Clear modular structure with a defined interface -> can abstract and hide away details.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Advantages of Constants

A
  • They have meaningful identifiers which make code easier to follow and maintain
  • Constants only have to be updated in one place if the value changes.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

“Inherits” meaning

A

The child class gains all of the non-private methods of the parent and all of the attributes of the parent.

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

What is Aggregation Association?

A
  • Weaker association
  • The child class cannot exist independently of the parent class
  • Real-life example: A person in a car
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is Composition association?

A
  • Stronger association
  • The child class cannot exist independently of the parent class.
  • Real-life example: A wheel of a car
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is encapsulation?

A
  • Used to hide data and methods, which prevents them from being accessed and changed.
  • Distinguishes attributes/methods as public, protected and private.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a public method / attribute ?

A

A method/attribute accessible from outside the class.

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

What is a private method/attribute?

A

Private methods/attribute are accessible in their own class

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

How can you access private attributes?

A

Using a defined method, e.g. GetSymbol()

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

What are protected methods / attributes?

A

Only current class can access methods / attributes.

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

What programming language doesn’t recognise protected attributes / methods?

A

Python!

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

How can you update private attributes?

A

Using a setter method.

E.g. ChangeSymbolInCell()

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

What is Overriding?

A

When a method in a child class overrides a method or attribute in a parent class.

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

What is Polymorphism?

A

Allows us to have a function that can take on many forms of its parameters by using overriding.

E.g. the built in function len ()

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

What is a static attribute?

A

Static attributes are defined for the class and can be accessed without creating an object instance.

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

What is an abstract method?

A

The method isn’t supplied in the base class, which forces the method to be implemented in the subclass (child class)

15
Q

What is a static method?

A

A method that doesn’t need to be accessed through object instantation.

16
Q

What is a virtual method?

A

A method defined in a superclass that can be overridden by methods in a subclass.

17
Q

What is the difference between an abstract and virtual method?

A

Virtual methods have implementation, whereas abstract methods do not.

18
Q

What is special about every method in Python?

A

All methods in Python are virtual.

19
Q

What is an interface?

A

A class containing abstract methods. It enforces classes to have a fixed set of methods, with the methods being run from the class and not the interface.

20
Q

How do you indicate inheritance in a UML class diagram?

A

Have the child class pointing to the parent class using an arrow with its head shaded in.

21
Q

How do you indicate composition in a UML class diagram?

A

Using an arrow with its head as a shaded in black diamond.

22
Q

How do you indicate aggregation in a UML class diagram?

A

Using an arrow with its head as a white diamond.

23
Q

How do you indicate that an attribute / method in a UML class diagram is public?

A

Use a plus sign ( + )

24
Q

How do you indicate that an attribute / method in a UML class diagram is protected?

A

Use a hashtag ( # )

25
Q

How do you indicate that an attribute / method in a UML class diagram is private?

A

Use a minus sign ( - )

26
Q

What are the benefits of composition over inheritance?

A
  • Each class can be tested more easily using composition. It isn’t possible to test a child class independently from a parent class using inheritance.
  • There can be side effects for child classes if a method in the parent class is changed.
27
Q

What is the benefit of using encapsulation?

A

Allows programmers to make future changes to the code more easily, as making private attributes and methods protects other parts of the code from change.

28
Q

What is the benefit of using interfaces instead of implementation?

A

Allows programmers to have a framework for all of the classes, as it allows a way to find commonality between unrelated classes that need common methods.