Defining Class and Creating Objects
When we define any class, we are not defining any data, we just define a structure or a blueprint, as to what the object of that class type will contain and what operations can be performed on that object.
Below is the syntax of class definition,
// member function defintion
Here is an example, we have made a simple class named Student with appropriate members,
So its clear from the syntax and example, class definition starts with the keyword "class" followed by the class name. Then inside the curly braces comes the class body, that is data members and member functions, whose access is bounded by access specifier. A class definition ends with a semicolon, or with a list of object declarations.
B are the objects of class
Student, declared with the class definition. We can also declare objects separately, like we declare variable of primitive data types. In this case the data type is the class name, and variable is the object.
// creating object of class Student
B will have their own copies of data members i.e.
name and we can store different values for them in these objects.
Want to learn coding and don't know where to start?
Try out our Interactive Courses for Free 🥳 😯 🤩