Page 20 - CA_Blue( J )_Class9
P. 20
1.3 PRINCIPLES OF OBJECT-ORIENTED PROGRAMMING
As you know Encapsulation, Data Abstraction, Inheritance and Polymorphism are the four pillars of Object-Oriented
Programming. Let us learn about them in detail.
Principles of
Object-Oriented Programming
1.3.1 Encapsulation
Encapsulation is one of the basic concepts of object-oriented programming (OOP).
The wrapping up of data members and member functions together into a single Methods Variables
unit is called encapsulation. It means that data can be accessed in the associated
function only and safe from outside interference and misuse thus leading to the CLASS
important concept of OOP known as data hiding. Concept of Encapsulation
A real-life example is a capsule. In general, a capsule is a small case or container, especially round or cylindrical in
shape which protects the drug inside it from getting contaminated with the dust particles from outside.
Similarly, Methods and Variables are enclosed within a unit called class.
Example of Encapsulation using class:
Both Data Members and Member Methods are defined within the body of the class country.
class country Class name
{
String name;
String capital; Data Members
void input ()
{
name= "India" ; Member Methods
capital= "New Delhi";
}
void display ()
{
System.out.println ("Name of the Country "+name);
System.out.println ("Name of Capital" +capital);
}
}
18 Touchpad Computer Applications-IX

