cs p2

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/89

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 3:46 PM on 4/18/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

90 Terms

1
New cards

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).

2
New cards

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.

3
New cards

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.

4
New cards

State two benefits of inheritance.

Reduces code duplication/repetition; promotes code reuse; allows extending existing functionality without rewriting; supports polymorphism.

5
New cards

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.

6
New cards

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.

7
New cards

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.

8
New cards

Define abstraction.

"Abstract representation of features of a real-world entity; hides implementation detail

9
New cards

Define constructor.

Special method called when an object is created (instantiated); initialises instance variables; has same name as the class; no return type.

10
New cards

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.

11
New cards

Define accessor method.

Public method that returns the value of a private attribute; getter; enforces encapsulation by controlling read access; e.g. getName().

12
New cards

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).

13
New cards

Define method signature.

"The method name together with the number

14
New cards

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.

15
New cards

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.

16
New cards

Define instance (of a class).

"A specific object created from a class; has its own copy of instance variables; class is the blueprint/template

17
New cards

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.

18
New cards

Define primitive data type.

"Basic built-in data type that stores a single value directly in memory; not an object; e.g. int

19
New cards

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.

20
New cards

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.

21
New cards

Define public (access modifier).

"Access modifier making a member accessible from any class; used for methods that form the class's interface (constructors

22
New cards

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.

23
New cards

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.

24
New cards

Define identifier.

"Name given to a programming element (variable

25
New cards

UML class diagram structure.

"Three stacked compartments: top=class name (bold)

26
New cards

UML notation for an attribute.

"- attributeName : dataType (private); e.g. - name : String

27
New cards

UML notation for a method.

"+ methodName(param : type) : returnType; e.g. + getName() : String

28
New cards

UML inheritance arrow.

Solid line with hollow triangle arrowhead pointing from subclass to superclass; indicates 'is-a' relationship.

29
New cards

UML association arrow.

"Solid line with open arrowhead between two classes; indicates one class uses/refers to another; multiplicity labels (1

30
New cards

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; } }

31
New cards

Java constructor pattern.

"public ClassName(type1 p1

32
New cards

Java create object instance.

ClassName objName = new ClassName(args); // new calls the constructor; objName is a reference to the new object.

33
New cards

Java accessor/mutator pattern.

public Type getAttr() { return attr; } public void setAttr(Type v) { this.attr = v; }

34
New cards

Java array declaration and size.

DataType[] arr = new DataType[N]; // size fixed once created; arr.length gives size; indices 0 to N-1.

35
New cards

Java traverse array.

"for (int i = 0; i < arr.length; i++) { /* use arr[i] / } OR for (DataType item : arr) { / use item */ }"

36
New cards

Identify two essential features of a recursive method.

Base case (terminating condition that does not recurse); recursive call that moves toward the base case.

37
New cards

Java recursive factorial.

public int factorial(int n) { if (n <= 1) return 1; else return n * factorial(n - 1); }

38
New cards

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

39
New cards

Why is recursion suitable for tree traversal or palindrome check?

"Problem has self-similar structure (smaller subtree

40
New cards

Java try-catch block.

try { /* risky code / } catch (ExceptionType e) { / handle / } finally { / always runs */ }

41
New cards

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.

42
New cards

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.

43
New cards

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; } }

44
New cards

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);"

45
New cards

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());"

46
New cards

Identify two features of an abstract data type (ADT).

"Data structure defined by its operations/behaviour

47
New cards

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.

48
New cards

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.

49
New cards

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.

50
New cards

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.

51
New cards

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.

52
New cards

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

53
New cards

Outline the implication of declaring a method or variable as static.

"Belongs to the class

54
New cards

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.

55
New cards

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).

56
New cards

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.

57
New cards

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.

58
New cards

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.

59
New cards

Compare interface and abstract class.

"Interface: only method signatures

60
New cards

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.

61
New cards

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.

62
New cards

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().

63
New cards

Java: method overloading.

"public void print(String s) { System.out.println(s); } public void print(int n) { System.out.println(n); } // same name

64
New cards

Java: override a superclass method.

@Override public String toString() { return 'custom output'; } // subclass provides new implementation; @Override annotation documents intent.

65
New cards

Java: iterate through ArrayList.

"for (int i = 0; i < list.size(); i++) { Type item = list.get(i); /* process / } OR for (Type item : list) { / process */ }"

66
New cards

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;"

67
New cards

Java: traverse linked list iteratively.

Node curr = head; while (curr != null) { /* process curr.getData() */ curr = curr.getNext(); }

68
New cards

Java: recursive sum of array.

"public int sum(int[] a

69
New cards

Java: search ArrayList for object by attribute.

for (Type obj : list) { if (obj.getId().equals(target)) return obj; } return null;

70
New cards

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++; }"

71
New cards

Java: swap two array elements.

"Type temp = arr[i]; arr[i] = arr[j]; arr[j] = temp;"

72
New cards

Java: check string is empty or null safely.

"if (s == null || s.length() == 0) { /* empty */ }"

73
New cards

"Construct UML for class Person with name

age

74
New cards

UML relationship: Car extends Vehicle.

Solid line from Car to Vehicle ending in hollow triangle arrowhead pointing at Vehicle (inheritance/generalisation).

75
New cards

UML relationship: Cart contains POSline objects.

"Cart ----<> POSline (hollow diamond at Cart end = aggregation; '1' near Cart and '*' near POSline for multiplicity)."

76
New cards

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'.

77
New cards

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

78
New cards

Compare static and instance variables.

"Static: one copy shared by all instances

79
New cards

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.

80
New cards

Compare primitive type and reference type.

"Primitive: stores value directly (int

81
New cards

Compare linked list and array for implementing a stack.

"Array: fixed size

82
New cards

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.

83
New cards

Command Define (P2): mark breakdown.

1-2 marks typically; one-sentence precise meaning using key OOP vocabulary; no examples unless asked.

84
New cards

Command Construct UML (P2): mark breakdown.

"3-4 marks usually; marks for: class name box

85
New cards

Command Construct method (P2): mark breakdown.

"3-6 marks; marks typically for method signature

86
New cards

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.

87
New cards

Command Outline (P2): how to answer.

"2 marks typically: 1 for the point

88
New cards

Command Explain (P2): how to answer.

"3-5 marks; structure: make a point

89
New cards

Command Describe (P2): how to answer.

Detailed account in context; typically 2-4 marks; name mechanism + how it works + effect; use correct OOP terms.

90
New cards

Command Discuss (P2): how to answer.

6 marks; give both sides (advantages and disadvantages); link each to the scenario; end with a reasoned position.