Repaso
Español
Design & PracticesFoundationsDP-65

Explain what a class, an object, a field and a method are to a beginner.

Answer

  • A class is a blueprint (for example Bicycle): it describes what every bicycle has and can do.
  • An object is one real thing created from that blueprint (Bicycle bike1 = new Bicycle();). Two objects from the same class keep their own data.
  • Fields store the state of the object: speed, gear.
  • Methods are its behavior, the actions it can perform: speedUp(), applyBrakes().
  • Encapsulation: keep the fields private and let others use the object only through its methods.

Key terms

Practice this question in Repaso