Home / Definitions / Class Keyword

Class Keyword

Jenna Phipps
Last Updated May 24, 2021 8:02 am

A class keyword in programming is an indicator that declares a certain class. In object-oriented programming, a class contains and designs objects, holding an object’s informational data and its behavioral patterns (what it can do). These behaviors are also known as methods: processes that are related to the object in question. For example, if a programmer wanted to create a class for the object refrigerator, the class could contain information about the refrigerator:

  • its stainless steel exterior
  • the three shelves
  • a produce drawer

as well as related methods and behaviors:

  • cooling the food by maintaining a specific temperature
  • opening the refrigerator and placing food inside
  • using the ice dispenser to get a drink

The class keyword (simply the word class before anything else) initiates a class declaration and is required before any class. The title of the class follows the keyword:

class Refrigerator { }

All other data and methods (or functions) of the class refrigerator fall between the brackets.

The class keyword and the following class title are the only prefixes required for a class. However, there are optional features that programmers can use to define a class. Programmers can create a class that is public or private and can also denote a superclass of which the current class is a part.