Comp 110 Class Definition

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)
class <name> {
   // Field(s)
   <type> _<fieldName>;
   // Constructor(s)
   <classname>(<parameter list>) {
     // Constructor body elided
   }
   // Method(s)
   <returnType> <methodName>(<parameter list>) {
     // Method Body elided
   }
}

Declaring and Defining a Class

In the image above the first line, "class <name>", is the proper way to declare a class. <name> can be replaced with whatever you want the name of your class to be. For example, in lecture we had a class named "Robot".