Circle Class Inheritance
Part of the Object Oriented Programming section of Coddy's JavaScript journey — lesson 40 of 56.
Challenge
Your task is to create a Circle class that inherits from the Shape class.
- In the file called
Circle.jsimport theShapeclass at the top:import { Shape } from './Shape.js'; - Create a
Circleclass thatextends Shapeand export it - The constructor should take two parameters:
colorandradius - Call
super(color)to initialize the parent class - Store the
radiusas a property:this.radius = radius - Import the `Circle` class in the main file
Try it yourself
import { Shape } from './Shape.js';
// TODO: Import the `Circle` class
// Tests
const basicShape = new Shape('red');
console.log(basicShape.describe()); // "A red shape"
const myCircle = new Circle('blue', 10);
console.log(myCircle.describe()); // Should output: "A blue shape"All lessons in Object Oriented Programming
1Objects & The this Keyword
Quick Review: ObjectsAdding Methods to ObjectsUnderstanding the this KeywordConstructor FunctionsThe new KeywordRecap Challenge7 Inheritance & The extends Key
InheritanceThe "is-a" RelationshipThe extends KeywordThe super() MethodInheriting Properties&MethodsRecap Challenge2Organizing Code
What are Modules?Exporting with exportImporting with importDefault vs. Named Exports8Organizing OOP Code
Organize Classes into Modules11Project: A Shape Renderer
Setup: Shape Class & ExportCircle Class Inheritance9Static Methods & Properties
Class-Level vs. Instance-LevelStatic PropertiesStatic Utility MethodsRecap challenge