1/89
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
Define encapsulation.
Bundling data and the methods that operate on that data into one class unit; data is hidden from outside access and reached only via accessor/mutator methods (dot notation).
State two benefits of encapsulation.
Data hiding protects internal state from accidental modification; internal implementation can change without affecting external code; improves security; eases debugging.
Define inheritance.
OOP feature where a subclass (child) inherits attributes and methods of its superclass (parent); promotes code reuse; new classes can extend existing ones.
State two benefits of inheritance.
Reduces code duplication/repetition; promotes code reuse; allows extending existing functionality without rewriting; supports polymorphism.
State two drawbacks of inheritance.
Tight coupling between parent and child classes; deep hierarchies hard to debug/maintain; child class locked to one parent; improper overriding can break behaviour.
Define polymorphism.
Ability of objects of different classes to respond to the same method call in their own way; usually via method overriding in subclasses; single interface multiple implementations.
Outline one advantage of polymorphism.
Code is open for extension but closed for modification; new subclasses can be added without changing existing code; improves maintainability and flexibility.
Define abstraction.
"Abstract representation of features of a real-world entity; hides implementation detail
Define constructor.
Special method called when an object is created (instantiated); initialises instance variables; has same name as the class; no return type.
Why can a class have more than one constructor?
Constructor overloading: multiple constructors with different parameter lists; allows flexible object creation depending on which data is available; method signatures differ so no conflict.
Define accessor method.
Public method that returns the value of a private attribute; getter; enforces encapsulation by controlling read access; e.g. getName().
Define mutator method.
Public method that modifies the value of a private attribute; setter; enforces encapsulation by controlling write access; e.g. setName(String n).
Define method signature.
"The method name together with the number
Define static variable.
Class variable belonging to the class rather than any instance; shared by all objects of the class; exists without any object being created; accessed via ClassName.variable.
Why use a static variable?
When a value should be shared by every instance (e.g. a counter of how many objects exist); changing it changes it for all instances; does not require an instance to access.
Define instance (of a class).
"A specific object created from a class; has its own copy of instance variables; class is the blueprint/template
Difference between a class and an instance.
Class: blueprint/template defining attributes and methods; no data. Instance: object created from the class using the constructor; holds actual values for each attribute.
Define primitive data type.
"Basic built-in data type that stores a single value directly in memory; not an object; e.g. int
Define object reference.
Variable that stores the memory address/location of an object rather than the object itself; assigning one reference to another makes both point to the same object.
Define private (access modifier).
Access modifier restricting visibility to within the declaring class only; used for attributes to enforce encapsulation; not accessible from other classes including subclasses.
Define public (access modifier).
"Access modifier making a member accessible from any class; used for methods that form the class's interface (constructors
Define protected (access modifier).
Access modifier allowing access within the class subclasses and same package; used when subclasses need to inherit attributes without making them fully public.
Define parameter variable.
Variable declared in a method's parameter list; receives a value (argument) passed when the method is called; local to the method; ceases to exist when method returns.
Define identifier.
"Name given to a programming element (variable
UML class diagram structure.
"Three stacked compartments: top=class name (bold)
UML notation for an attribute.
"- attributeName : dataType (private); e.g. - name : String
UML notation for a method.
"+ methodName(param : type) : returnType; e.g. + getName() : String
UML inheritance arrow.
Solid line with hollow triangle arrowhead pointing from subclass to superclass; indicates 'is-a' relationship.
UML association arrow.
"Solid line with open arrowhead between two classes; indicates one class uses/refers to another; multiplicity labels (1
Java class declaration template.
public class ClassName { private DataType attr; public ClassName(params) { this.attr = param; } public DataType getAttr() { return attr; } public void setAttr(DataType v) { this.attr = v; } }
Java constructor pattern.
"public ClassName(type1 p1
Java create object instance.
ClassName objName = new ClassName(args); // new calls the constructor; objName is a reference to the new object.
Java accessor/mutator pattern.
public Type getAttr() { return attr; } public void setAttr(Type v) { this.attr = v; }
Java array declaration and size.
DataType[] arr = new DataType[N]; // size fixed once created; arr.length gives size; indices 0 to N-1.
Java traverse array.
"for (int i = 0; i < arr.length; i++) { /* use arr[i] / } OR for (DataType item : arr) { / use item */ }"
Identify two essential features of a recursive method.
Base case (terminating condition that does not recurse); recursive call that moves toward the base case.
Java recursive factorial.
public int factorial(int n) { if (n <= 1) return 1; else return n * factorial(n - 1); }
Java recursive palindrome check.
"public boolean palindrome(String s) { if (s.length() <= 1) return true; if (s.charAt(0) != s.charAt(s.length()-1)) return false; return palindrome(s.substring(1
Why is recursion suitable for tree traversal or palindrome check?
"Problem has self-similar structure (smaller subtree
Java try-catch block.
try { /* risky code / } catch (ExceptionType e) { / handle / } finally { / always runs */ }
Purpose of exception handling.
Catches runtime errors gracefully without crashing the program; separates error-handling code from normal logic; allows recovery or user-friendly error messages.
Why choose linked list over array for a dynamic customer list?
Dynamic size: customers can be added/removed without resizing; efficient insertion/deletion (just update pointers); no wasted memory when empty.
Java-style linked list node class.
public class Node { private Data data; private Node next; public Node(Data d) { this.data = d; this.next = null; } public Data getData() { return data; } public Node getNext() { return next; } public void setNext(Node n) { this.next = n; } }
Algorithm: add node to end of linked list.
"if head == null then head = newNode; else curr = head; while (curr.getNext() != null) curr = curr.getNext(); curr.setNext(newNode);"
Algorithm: remove first node matching value X.
"if (head.getData() == X) { head = head.getNext(); return; } prev = head; curr = head.getNext(); while (curr != null && curr.getData() != X) { prev = curr; curr = curr.getNext(); } if (curr != null) prev.setNext(curr.getNext());"
Identify two features of an abstract data type (ADT).
"Data structure defined by its operations/behaviour
Outline one advantage of modularity in program development.
Large problem broken into smaller manageable parts; modules can be developed/tested independently; enables code reuse; easier to maintain and debug.
State three advantages of modularity.
Separation of concerns (each module has one responsibility); parallel development by multiple programmers; easier debugging and testing; reusable components; simpler maintenance.
State two advantages of using existing libraries.
Saves development time (code already written and tested); tested/debugged by many users so reliable; standardised interface; benefit from performance optimisations; reduces bugs.
Outline the nature of an object.
An instance of a class; occupies memory; has state (attribute values) and behaviour (methods); accessed via a reference variable.
Outline data hiding as a security feature in OOP.
Private attributes cannot be accessed directly from outside the class; changes controlled through mutator methods which can validate input; prevents unauthorised or invalid modification of data.
Explain the importance of naming conventions and coding style.
"Makes code readable/understandable by other developers; easier to maintain and debug; reduces errors from misinterpretation; supports team collaboration; professional standard (camelCase for variables/methods
Outline the implication of declaring a method or variable as static.
"Belongs to the class
Outline one advantage of binary search over linear search.
Much faster for large sorted collections: O(log n) vs O(n); each comparison halves the search space.
Outline one disadvantage of binary search.
Requires the data to be sorted first; not suitable for dynamic/frequently-updated data; does not work on linked lists efficiently (no random access).
Define parallel arrays.
Two or more arrays where elements at the same index relate to the same real-world entity; e.g. names[i] and scores[i] both belong to the i-th student.
Identify two features of modern programming languages.
Object-oriented support; garbage collection / automatic memory management; standard libraries/APIs; exception handling; Unicode/extended character sets; type safety.
State two aims of the open source movement.
Freely accessible source code; collaborative development; ability to modify and redistribute software; transparency; community support; avoidance of vendor lock-in.
Compare interface and abstract class.
"Interface: only method signatures
Define association.
Relationship between two classes where one uses/refers to the other; less permanent than aggregation; UML shown as a line between classes with optional multiplicity.
Define aggregation.
'Has-a' relationship where one class contains references to another but the contained object can exist independently; whole-part relationship; UML shown with hollow diamond at the whole.
Java: count objects of a class using static counter.
public class Thing { private static int count = 0; public Thing() { count++; } public static int getCount() { return count; } } // count increments for each new Thing; access via Thing.getCount().
Java: method overloading.
"public void print(String s) { System.out.println(s); } public void print(int n) { System.out.println(n); } // same name
Java: override a superclass method.
@Override public String toString() { return 'custom output'; } // subclass provides new implementation; @Override annotation documents intent.
Java: iterate through ArrayList.
"for (int i = 0; i < list.size(); i++) { Type item = list.get(i); /* process / } OR for (Type item : list) { / process */ }"
Java: find max value via linear scan.
"Type max = arr[0]; for (int i = 1; i < arr.length; i++) { if (arr[i].compareTo(max) > 0) max = arr[i]; } return max;"
Java: traverse linked list iteratively.
Node curr = head; while (curr != null) { /* process curr.getData() */ curr = curr.getNext(); }
Java: recursive sum of array.
"public int sum(int[] a
Java: search ArrayList for object by attribute.
for (Type obj : list) { if (obj.getId().equals(target)) return obj; } return null;
Java: copy array elements matching a criterion to new array.
"int count = 0; for (Type x : src) if (condition(x)) count++; Type[] dest = new Type[count]; int j = 0; for (Type x : src) if (condition(x)) { dest[j] = x; j++; }"
Java: swap two array elements.
"Type temp = arr[i]; arr[i] = arr[j]; arr[j] = temp;"
Java: check string is empty or null safely.
"if (s == null || s.length() == 0) { /* empty */ }"
"Construct UML for class Person with name
age
UML relationship: Car extends Vehicle.
Solid line from Car to Vehicle ending in hollow triangle arrowhead pointing at Vehicle (inheritance/generalisation).
UML relationship: Cart contains POSline objects.
"Cart ----<> POSline (hollow diamond at Cart end = aggregation; '1' near Cart and '*' near POSline for multiplicity)."
Compare class and object.
Class: template/blueprint defining attributes and methods; no actual data. Object (instance): a specific creation from the class with its own values; occupies memory; created with 'new'.
Compare procedural and object-oriented programming.
"Procedural: program structured as sequence of functions operating on data; top-down approach. OOP: program structured as objects encapsulating data and behaviour; uses inheritance
Compare static and instance variables.
"Static: one copy shared by all instances
Compare accessor and mutator methods.
Accessor (getter): returns the value of a private attribute without changing it. Mutator (setter): takes a parameter and updates the value of a private attribute; can include validation.
Compare primitive type and reference type.
"Primitive: stores value directly (int
Compare linked list and array for implementing a stack.
"Array: fixed size
State two disadvantages of OOP.
Steep learning curve compared to procedural; performance overhead from object creation and method dispatch; over-engineering risk (complex class hierarchies); larger memory footprint.
Command Define (P2): mark breakdown.
1-2 marks typically; one-sentence precise meaning using key OOP vocabulary; no examples unless asked.
Command Construct UML (P2): mark breakdown.
"3-4 marks usually; marks for: class name box
Command Construct method (P2): mark breakdown.
"3-6 marks; marks typically for method signature
Command State (P2): how to answer.
One short line; for 'state relationship between X and Y' name the OOP relationship (inheritance/aggregation/association); for code output give exact printed text.
Command Outline (P2): how to answer.
"2 marks typically: 1 for the point
Command Explain (P2): how to answer.
"3-5 marks; structure: make a point
Command Describe (P2): how to answer.
Detailed account in context; typically 2-4 marks; name mechanism + how it works + effect; use correct OOP terms.
Command Discuss (P2): how to answer.
6 marks; give both sides (advantages and disadvantages); link each to the scenario; end with a reasoned position.