Repaso
Español
Java CoreFoundationsJV-46

In Java, what are a class and an object?

Bicycle bike1 = new Bicycle();
Bicycle bike2 = new Bicycle();

Options

  1. A class is a blueprint; an object is an instance made with new (Correct option)
  2. A class is a variable; an object is a file on disk
  3. An object is the blueprint; a class is one instance of it
  4. 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.

Key terms

Practice this question in Repaso