-
Notifications
You must be signed in to change notification settings - Fork 0
Unit 3 ‐ Lesson 1
This lesson is under construction.
In Lesson 1, we learned about types (int
, double
, etc.) and functions. In Lesson 2, we created our own functions. Now we will create our own types.
A type is defined by a piece of code called a class. You can think of a class as a blueprint or template. An object is a concrete, individual variable of a particular type. For example, I can have a Shoe
class which defines the Shoe
type. The Shoe
class defines what properties and functions a Shoe
has or can do, respectively.
A particular Shoe
is called an object, or an instance of an object. Different Shoe
s can have different properties, but not different kinds of properties; for example, all Shoe
s have a Color
, but one Shoe
can have a Color
equal to Black
where another Shoe
can have a Red
color, etc. In other words, the types of data stored within objects of the same type is invariant (Red
and Black
are both Color
s), but the stored data itself can vary between objects.
Technically, int
, double
, etc. are not objects but are primitive data types. Objects function pretty similarly though, in many ways, though there are some important differences between primitives and objects which we will discuss. However, for now, you can think of them as generally the same thing.