Comp 110 Classes

What is a class?

  • A class is a blueprint for a certain type of object.
  • An object’s class defines its properties (fields) and capabilities (methods)

Classes are made of...

  • Fields
    • Define what data its objects can store
    • All objects of the same type have the same fields but distinct values
  • Constructors
    • They are responsible for initializing an objects fields
    • Same name as the class it is declared in
    • Called when the new keyword is encountered.
  • Methods
    • specify the commands we can send to an object via method calls
    • Can access an object's fields
    • Can return values back to the caller