What is the relationship between a class and an object?
Options
- They are the same thing under two different names
- A class is a blueprint; an object is something built from it (Correct option)
- An object is a blueprint that is used to create classes
- Classes exist only at runtime and objects only in the code
Answer
A class is a blueprint; an object (instance) is a concrete thing built from it
Why
A class describes what data and behavior something has, like the plan of a house. An object is one real house built from that plan.
You can create many objects from one class, each with its own data: ana = User("Ana") and luis = User("Luis") are two objects of the class User.
Remember
Class = blueprint. Object = one thing built from it.