Page 71 - Modular_V1.1_Flipbook
P. 71
public:
int wheels;
int seats;
void getModel()
{
cout<<”Your car model is VXI”;
}
};
void main() {
Car c; // Creating an object of class Car Output:
// Access attributes and set values Wheels in your car is: 4
c.wheels = 4; Your car is: 5 seater
Your car model is VXI
c.seats = 5;
clrscr();
// Print attribute values
cout <<”Wheels in your car is: “<<c.wheels << “\n”;
cout <<”Your car is: “<< c.seats<< “ seater\n”;
//Calling function of the class
c.getModel();
getch();
}
PRINCIPLES OF OOP
C++ follows all the basic principles of object-oriented programming languages. The basic
principles of object-oriented programming are: data abstraction, encapsulation, inheritance and
polymorphism. Let us learn about these in detail.
Data Abstraction
Abstraction means to hide something. In programming, data abstraction refers to a process
of hiding the complex or unnecessary data and show only the data essential for the user. For
example, when you send a message on WhatsApp to your friend, you just type the message and
then tap on the send button. The phone shows you that the message has been sent. The internal
processing of sending the message is hidden from you as it is not relevant to you.
Encapsulation
Encapsulation refers to a process of binding data and function together into a single unit like
capsule. The encapsulation is used to restrict the accessibility of private data members from
outside the class. To implement encapsulation, make all data members of a class private and
functions public. You can use the private keyword of C++ to make a data member private.
OOP Concepts 69

