Fundamentals of Programming Flashcards

1
Q

What is Iteration?

A

Repeating an instruction, this could be definite or indefinite.

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

What is the difference between definite iteration and indefinite iteration?

A

With definite iteration, the number of repetitions is known before the loop starts, however with indefinite iteration, the amount of repetitions is not known beforehand.

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

What is selection?

A

Comparing values and choosing an action based on those values.

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

def func(x)
return x + 2
func(5)

in the code above, what is the parameter and what is the argument?

A

x is the parameter and 5 is the argument

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

Why are local variables better to use than global variables?

A

local variables are more memory efficient, they also keep you code more modular.

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

What is a stack frame (in subroutine calls)

A

Stack frames are used by computers to store return addresses, parameters and local variables for each subroutine call that occurs during the execution of a program.

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

What is the difference between a public and private property/method in a class

A

private properties/methods can only be accessed from within an object, however public methods allow an interface for accessing and modifying a class’s private properties

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

What is encapsulation?

A

the process of combining methods and procedures to form an object. An object is said to encapsulate its contents, forming a single entity which encompasses all of the objects properties and methods.

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

What is inheritance

A

Classes can inherit from other classes. Inheritance allows one class to share the properties and methods of another class while having its own properties and methods too

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

What is polymorphism

A

Polymorphism occurs when objects are processed differently depending on their class. Two classes with methods that have the same name, but do different things.

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

What is overriding

A

An overrien method has the same name as a method in an inherited class but different implementation

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

What is association

A

If two objects are associated, they can be described as having a “has a” relationship. e.g for two classes Car and Driver, a Car has a Driver. There are two types of association, aggregation and composition.

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

What is Aggregation (type of association)

A

Aggregation is the weaker of the two kinds of association. When an object is associated with another by aggregation, it will still exist if its containing object is destroyed. e.g a car’s driver is associated with the car by aggregation. If the car is destroyed, the driver still exists.

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

What is composition (type of association)

A

If two objects are associated by composition and the containing object is destroyed, the associated object is also destroyed. e.g a car’s wheels is associated with the car by composition. If the car is destroyed, so are the wheels.

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

Why is OOP used

A

OOP provides programs with a clear structure that makes developing and testing programs easier for developers. It also allows code to be reused throughout the same program and even in other programs.

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

What name is given to the code which is run to handle an exception?

A

Catch block

17
Q

What name is given to a type of subroutine which always returns a value

A

Function

18
Q

What is meant by a base case?

A

The terminating situation in recursion that does not use recursion to produce a result.

19
Q

What error will occur if a recursive subroutine never meets its base case?

A

Stack overflow

20
Q

Name 3 OOP design principles

A

Encapsulate what varies

Favour composition over inheritance

Program to interfaces, not implementation

21
Q

In class diagrams which type of line represents aggregation?

A

A line with a hollow diamond on the end

22
Q

In class diagrams which type of line represents composition?

A

A line with a solid diamond on the end