1/81
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
What is a class?
A blueprint or template that defines the data and methods objects of that type will have. It is the code definition — not a real object. Like architectural drawings before any house is built.
What is an object?
A specific instance created from a class. Each object has its own copy of the instance variables. Multiple objects can exist from one class
What is instantiation?
The process of creating an object from a class. Memory is allocated for the new object and the constructor runs automatically. Done in Java with the new keyword.
What is a constructor?
A special method that runs automatically when an object is created. In Java
What is an instance variable (attribute/property)?
A variable stored inside each object. Every object of the same class gets its own separate copy. Also called a property or field — it describes the object's state.
What is a method?
A function that belongs to a class. It defines what an object can DO. Methods can access and modify the instance variables of the object they belong to. Also called behaviours.
What is encapsulation?
Wrapping data (attributes) and the methods that use that data together into a single unit (the class)
What is an accessor (getter)?
A method that allows code outside the class to READ the value of a private attribute. Returns the value without letting external code change it directly. Named with get prefix by convention.
What is a mutator (setter)?
A method that allows code outside the class to WRITE (change) the value of a private attribute. Can include validation before setting. Named with set prefix by convention.
What does private mean?
An access modifier. A private attribute or method can only be accessed from within the same class. External code cannot read or change it directly — must use accessors/mutators.
What does public mean?
An access modifier. A public method or attribute can be accessed from any class in the program. Accessor/mutator methods and behaviours are usually public.
What does static mean?
The variable or method belongs to the CLASS itself
What does this mean in Java?
A keyword used inside a class to refer to the CURRENT object. Needed when a parameter name and an instance variable share the same name (e.g. this.name = name).
What is inheritance?
A mechanism where a child class (subclass) automatically receives all non-private attributes and methods of a parent class (superclass). The child can add new features or change existing ones. Java: extends keyword.
What does super() do?
Calls the parent (superclass) constructor from inside a child class constructor. Must be the first line in the child constructor. Passes required parameters up to the parent.
What is polymorphism?
The ability for objects of different classes to respond to the same method call in their own specific way. Achieved through overriding (same name
What is overriding?
When a child class provides its OWN version of a method that already exists in the parent class. The child's version replaces the parent's for that object type. Same method name
What is overloading?
When a class has multiple methods with the SAME name but DIFFERENT parameter lists (different types or number of parameters). Java decides which version to run based on the arguments passed.
What is an abstract class?
A class that cannot be instantiated directly — you can never do new AbstractClass(). It defines method signatures that subclasses MUST implement. Acts as a contract. Java: abstract keyword.
What is aggregation?
A "has a" relationship where one class contains an object of another class as an instance variable
What is a dependency (uses) relationship?
One class uses another temporarily — typically as a method parameter that is not stored as an instance variable. In UML: dashed arrow + "uses" label.
What is an association (has a) relationship?
Two classes have an ongoing relationship but can exist independently. Often one-to-many. In UML: double-headed arrow + "has a" label.
What is a method signature?
The combination of a method's NAME and its PARAMETER LIST (types and order). The return type is NOT part of the signature. Used to distinguish between overloaded methods.
What is a UML class diagram?
A visual diagram showing classes as 3-row boxes (name / attributes / methods) and the relationships between them using specific arrow types. Used to plan and communicate OOP design.
In UML notation
what does – (minus) mean?
In UML notation
what does + (plus) mean?
In UML notation
what does # (hash) mean?
How do you write an attribute in UML format?
– attributeName: type (e.g. – registration: String) for private. Use + for public.
How do you write a method in UML format?
What arrow type represents inheritance in UML?
Solid arrow with hollow arrowhead pointing from child UP to parent. Label: "is a". Example: Car —is a→ Vehicle
What arrow type represents aggregation in UML?
Hollow diamond on the "owner" side with an arrow pointing to the owned class. Label: "has a". Example: ParkingArea ◇—has a→ Vehicle
What arrow type represents dependency in UML?
Dashed arrow. Label: "uses". Example: Borrower - - uses - -→ Book
What Java keyword is used for inheritance?
extends (e.g. class Car extends Vehicle)
What Java keyword is used to call the parent constructor?
super() — must be the FIRST line in the child class constructor.
What is the output of: Vehicle v = new Vehicle("X1234567")
v.setBroken(true)
System.out.println(v.getRegistration())
X1234567 — the constructor stores the registration
What does this.name = name mean inside a constructor?
this.name refers to the instance variable. name (right side) is the constructor parameter. this. is needed because both have the same identifier.
What happens when you call `new WaterMonster("Splashy"
25)if WaterMonster callssuper(name
Write the array-add pattern in Java (add item to next empty slot
return index
i < items.length
i++) { if (items[i] == null) { items[i] = x
return i
} } return -1
}
Write the array-add pattern using a counter variable (monsterCount style).
public void addItem(Item x) { if (count < items.length) { items[count] = x
count++
} else { System.out.println("Full")
} }
Write the array-remove-and-shift pattern in Java (find item
shift remaining elements left
for (int i = 0
i < count
i++) { if (items[i] == x) { idx = i
} } for (int j = idx
j < count - 1
j++) { items[j] = items[j+1]
} items[count-1] = null
count--
}
Write the array-search-and-return pattern in Java (search by String ID
return object or null).
i < count
i++) { if (items[i] != null && items[i].getID().equals(id)) { return items[i]
} } return null
}
How do you instantiate a subclass called FireMonster with name "Flamey" and 40 health?
FireMonster f = new FireMonster("Flamey"
Give two advantages of OOP (with expansion — mark scheme style).
Give two disadvantages of OOP (with expansion — mark scheme style).
Give two advantages of modularity (with expansion — mark scheme style).
Outline one advantage of making instance variables private.
Data hiding / increased security. This prevents accidental or unauthorised changes to variables from outside the class — any modification must go through a setter method
What is the mark scheme answer for "outline why this is used in setBroken"?
this is needed to distinguish the instance variable broken from the parameter also named broken. Without it
What is the mark scheme answer for "outline why super is used in the WaterMonster constructor"?
super() is a reference to the superclass (Monster). It calls the Monster constructor
What is the mark scheme answer for "outline one effect of the static modifier"?
The variable belongs to the class
Distinguish between a class and an object.
Class: a code definition / template / blueprint — only one exists in memory for static elements. Object: an actual instance created from the class — there can be many objects
What does it mean for Vehicle[] to be a "valid type" for an array that stores both Car and Motorbike objects?
Because Car and Motorbike both extend Vehicle (are subclasses of Vehicle)
What are the two types of methods that allow access to private variables?
Accessor (getter) and mutator (setter). Also accepted: get/set methods.
What is the difference between overriding and overloading?
Overriding: same method name AND same parameters
How do you write a constructor in Java?
Same name as the class
}`
What is the relationship between Car and Vehicle if class Car extends Vehicle?
Inheritance — "is a" relationship. Car is a subclass (child). Vehicle is the superclass (parent). Car inherits all non-private attributes and methods from Vehicle.
What is the relationship between ParkingArea and Vehicle if ParkingArea stores a Vehicle[] array?
Aggregation — "has a" relationship. ParkingArea owns/contains Vehicle objects. ParkingArea depends on Vehicle but Vehicle does not depend on ParkingArea