Introduction to Classes
Learn about classes using object-oriented methodology.
Building blocks of object-oriented programming
Class is the building block of a program built using the object-oriented methodology. Such programs consist of independent, self-managing modules and their interactions. An object is an instance of such a module created at runtime, and a class is its definition.
Class definition and instantiation
A class definition includes the declaration of its data members (data variables) and member functions (class functions), whereas instantiation is the process of creating an actual object. This object can then be used to access the data members and member functions defined in the class.
A keyword class is used with every declaration of class, followed by the name of the class. We can use any “className” you want, as long as it follows the naming rules that we defined previously in the context of variables.
We can also initialize our class data members at the time of declaration, like we can do with simple variables. Here’s how we can initialize our data members with default values for the class demoClass.
Let’s look at an example of creating a Dog class and using it to learn about classes in detail.