4.1 Fundamentals of programming Flashcards

(14 cards)

1
Q

What is the difference between a variable and a constant

A

constants are items of data whose
value does not change whereas variables are items of data whose
value could change while the
program is being run

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

What are the benefits of meaningful constant names

A

easier to find and correct errors/bugs in code, several programmers working on the same program at the same time so meaningful names makes it easier for everyone to understand and it will be easier to update the code later on when further versions of the
program are created

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

What are advantages of using named constants

A

if a constant is required multiple times throughout a program then using a constant means you only have to change one the value in one place

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

What are the advantages of using subroutines

A

subroutines can be reused since they’re independent of the main program
easier to debug - subroutines tested separately
code maintenance easier as only subroutines need to be updated

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

Describe the use of parameters

A

parameters are used to pass data between subroutines within program

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

What occurs during exception handling

A

when an error occurs an ‘exception’ is said to be thrown, when this happens the computer pauses execution of the program and saves the current volatile state of the program on the system stack, it then runs the catch block to prevent the program from crashing and informs user that an error has occurred, after the program uses the system stack to restore its previous state and resumes execution

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

What are local variables

A

a variable that is declared within a subroutine and can therefore only exist while the subroutine is executing and is only accessible within the subroutine

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

why is it good practice to use local variables

A

makes it easier to debug a program as the value of the variable can only be read or changed within one subroutine
it is also memory efficient as when a subroutine has finished running, the memory used for all local variables is removed.

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

What are global variables

A

variables that can be accessed from any part of a program and exist in memory for the entire duration of the program’s execution

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

What is a recursive subroutine

A

a subroutine which calls itself

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

what is an abstract method

A

a method that is declared in a class but has no implementation - it must be overridden in a subclass. It defines a contract for sub classes to implement specific behavior

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

what is a virtual method

A

a method in a base class that can be overridden by a subclass to provide a specific implementation. It allows polymorphism, meaning the method that gets called depends on the object’s actual type at runtime.

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

what is a static method

A

A static method belongs to the class rather than an instance, meaning it can be called without creating an object

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

difference between public, private and protected specifiers

A

Public: Accessible from anywhere in the program
Private: Accessible only within the same class
Protected: Accessible within the same class and sub classes

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