09.C++ Classes and Objects
09.C++ Classes and Objects
•
C++ Classes and Objects
Classes and objects are the two main aspects of object-oriented programming.
Look at the following illustration to see the difference between class and objects:
• private - members cannot be accessed (or viewed) from outside the class
The public setSalary() method takes a parameter (s) and assigns it to the salary
attribute (salary = s).
The public getSalary() method returns the value of the private salary attribute.
Inside main(), we create an object of the Employee class. Now we can use the
setSalary() method to set the value of the private attribute to 50000. Then we call
the getSalary() method on the object to return the value.
C++ Inheritance
In C++, it is possible to inherit
attributes and methods from one
class to another. We group the
"inheritance concept" into two
categories: