Paper 2 Questions Flashcards
Outline one effect of using the modifier static when declaring a variable.
Static means it is the same for all instances of the class:
because it is contained in the class rather than in an instance of the class/object / it is defined at the class level
Static means that less memory is taken up:
as only 1 memory allocation it created for all instances rather than 1 per instance
Describe the relationship between the classes Vehicle and ParkingArea.
public class ParkingArea {
private Vehicle vehicles[];
The answer is: Aggregation
Award [1] for aggregation (accept Composition also);
Award [1] for An instance of ParkingArea can contain Vehicles;
Award [1] for A single ParkingArea can contain between 0 and 300 instances of Vehicle;
Outline why it is necessary to use the keyword this in the setBroken method of the Vehicle class.
To distinguish between 2 variables with the same name;
Allows the local/instance variable to be set to the parameter/class variable;
Construct the method pay in the Car class, where it uses the vehicle method pay but adds the charge for the amount of time spent in the parking area.
Its an inheritance question that requires you to use a method from vehicle class, as the car class inherits features from the vehicle class
Firstly to use inhertied methods
you must first say super, then .(method name) then the parameters
so it would be like
super . pay (int hours)
Define mutator and acessor method
Acessesor emthod allows you to access encapulated variables
Accessor is a type of method that is used to retrieve private value of an attribute of an object without modifying the object itself.
while mutator method also known as setter method, Is a method that allows/controls changes to a private (hidden) variable;
Describe one feature of modern programming languages that allows the wide range of students’ names to be represented correctly.
Modern programming languages use Unicode to encode characters.
Which uses 16 bits / has about 64 000 characters.
Define object natural
an object is an abstract entity.
Which means that an object can be thought of as a data structure that encapsulates both data and behavior.
which has data/values and actions/methods
Dependecny vs aggregation
Dependency refers to a relationship between two classes where one class depends on the other class to perform a certain function or operation. In other words, a class cannot perform its task without the help of the other class.
so
outline one advantage of encapsulation.
Encapsulation means having private variables;
Variables not directly accessible from outside the class; Methods and variables are all included in the class definition;
So:
So that patient data cannot be accessed/modified accidentally;
So that patient data is more secure;
UML Diagram how do you put setters and getters
Setters have void return type
getters have return type
setters have parameters and getters do not have parameters
In relation to the Doctor object, outline the need for extended character sets as used
by modern programming languages.
Doctor name has accents which are not included in English language
Different languages use different characters, which are not included in the basic 8-bit ASCII character set;
Extended character sets (like Unicode) include all possible characters from all languages;
For example, the doctor’s name could not be spelled correctly in ASCII;