Menu
Coddy logo textTech

복습 챌린지

Coddy JavaScript 여정의 객체 지향 프로그래밍 섹션에 포함된 레슨 — 56개 중 38번째.

challenge icon

챌린지

Shape 클래스와 두 개의 자식 클래스가 주어집니다. 다형성 개념을 사용하여 완성하세요.

  1. Circle 클래스에서: describe()를 오버라이드하여 "This is a circle with radius [radius]"를 반환하도록 하세요.
  2. Square 클래스에서: describe()를 오버라이드하여 "This is a square with side [side]"를 반환하도록 하세요.

직접 해보기

import { Shape } from './shapes.js';
import { Circle } from './shapes.js';
import { Square } from './shapes.js';

// 테스트 코드 - 수정하지 마세요
const circle = new Circle(5);
const square = new Square(10);

console.log(circle.describe()); // 예상 결과: "This is a circle with radius 5"
console.log(square.describe()); // 예상 결과: "This is a square with side 10"

객체 지향 프로그래밍의 모든 레슨