4.1 Fundamentals of programming Flashcards
(14 cards)
What is the difference between a variable and a constant
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
What are the benefits of meaningful constant names
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
What are advantages of using named constants
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
What are the advantages of using subroutines
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
Describe the use of parameters
parameters are used to pass data between subroutines within program
What occurs during exception handling
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
What are local variables
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
why is it good practice to use local variables
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.
What are global variables
variables that can be accessed from any part of a program and exist in memory for the entire duration of the program’s execution
What is a recursive subroutine
a subroutine which calls itself
what is an abstract method
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
what is a virtual method
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.
what is a static method
A static method belongs to the class rather than an instance, meaning it can be called without creating an object
difference between public, private and protected specifiers
Public: Accessible from anywhere in the program
Private: Accessible only within the same class
Protected: Accessible within the same class and sub classes