Dog's constructor sets the name attribute to its argument. What happens when myDog = new Dog('Rex') runs?
- The Dog constructor is called.
- A new object is created.
- Its name attribute is set to 'Rex'.
Answer A new Dog object is created with name 'Rex'
A-level Computer Science revision · Programming
In object-oriented programming, a class is a template defining attributes (data) and methods (behaviour). An object is an instance of a class. A constructor method creates and initialises a new object. Each object has its own attribute values.
Watch out Each object holds its own values for its instance attributes; only class (static) attributes are shared.
Dog's constructor sets the name attribute to its argument. What happens when myDog = new Dog('Rex') runs?
Answer A new Dog object is created with name 'Rex'
What is an object?
What is the purpose of a constructor?
Explain the difference between an attribute and a method.
Answer An attribute is a variable that stores data about an object; a method is a subroutine that defines what the object can do.
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.