Comp 110 Classes: Overview

A class is a blueprint for an object. An object's class is what defines its properties and capabilities.

Classes are made up of 3 main parts:

1. Properties

Properties are the type of data an object can hold inside of it or encapsulate. Every object of the same class will have the same properties and these properties have the same default values.

2. Constructors

Constructors are called with the new keyword in order to create new instances of your objects. Constructor names also always match the Class name.

3. Methods

Methods define an object's capabilities. We have already encountered some examples of methods when working with strings.

Syntax for Class declaration and definition: 

Class <Name> {
    // Properties
    <propertyName> : <propertyType>;
    // Constructor
    <className> (<parameters>) {
        // elided
    // Methods
    <methodName>(<parameters>) : <returnType> {
        // elided