Exercise

Create your first class

Time to write your first class! In this exercise, you'll start building the Employee class you briefly explored in the previous lesson. You'll start by creating methods that set attributes, and then add a few methods that manipulate them.

As mentioned in the first video, an object-oriented approach is most useful when your code involves complex interactions of many objects. In real production code, classes can have dozens of attributes and methods with complicated logic, but the underlying structure is the same as with the most simple class.

Your classes in this course will only have a few attributes and short methods, but the organizational principles behind the them will be directly translatable to more complicated code.

Instructions 1/3

undefined XP
    1
    2
    3
  • Create an empty class Employee.
  • Create an object emp of the class Employee by calling Employee().

Try printing the .name attribute of emp object in the console. What happens?