Why use encapsulation?
- Attributes are private.
- They can only be changed through methods that validate input.
- This protects data and hides implementation.
Answer To protect data so it is changed only through controlled methods
A-level Computer Science revision · Programming
Encapsulation keeps attributes private and allows access only through methods (getters and setters), protecting data. Inheritance lets a subclass take the attributes and methods of a superclass and add its own. Polymorphism lets methods with the same name behave differently for different classes, for example by overriding.
Watch out Overriding redefines an inherited method in a subclass; it does not delete the superclass method.
Why use encapsulation?
Answer To protect data so it is changed only through controlled methods
Class Car inherits from class Vehicle. Which is true?
Shape.area() is redefined in Circle and Square to calculate each area. This is:
Give one advantage of inheritance.
Answer Common code is written once in the superclass and reused by subclasses, reducing duplication and making changes easier.
A-level Computer Science Pro, OCR H446
£119 once
Price rises to £199 on 1 January. Save £80 by joining before then.
At least 12 months of access
No VAT is charged.