Counting Instances Created from a Class

Published by Helen Yu in

Write a Composer class that has three accessor methods:

  1. name
  2. dob
  3. country

Add an additional class method .count which counts the total number of instances created.

Examples

# Just finished writing the Composer class
Composer.count ➞ 0

c1 = Composer.new("Ludvig van Beethoven", 1770, "Germany")
Composer.count ➞ 1

c2 = Composer.new("Wolfgang Amadeus Mozart", 1756, "Austria")
c3 = Composer.new("Johannes Brahms", 1833, "Germany")
Composer.count ➞ 3

Notes

N/A

Watch a quick demo on how Edabit works.