In Java, what are a class and an object?
Bicycle bike1 = new Bicycle();
Bicycle bike2 = new Bicycle();Options
- A class is a blueprint; an object is an instance made with
new(Correct option) - A class is a variable; an object is a file on disk
- An object is the blueprint; a class is one instance of it
- They are the same thing under two different names
Answer
A class is a blueprint; an object is one instance created from it with new
Why
The Java tutorial: a class is the blueprint from which individual objects are created.
Here Bicycle is the class. bike1 and bike2 are two separate objects (instances), each with its own data: one can be at gear 2 while the other is at gear 3.
new creates a new object in memory.
Remember
Class = blueprint. Object = instance made with new.