Page 53 - iprime_V2.2_class8
P. 53
All the animals in the animal class have similar behaviours such as eating, drinking, and sleeping.
They also have similar properties, such as colour, size, and number of legs.
In the same way, a class in Java contains different types of objects that have similar properties
and behaviour. After declaring a class, we can create any number of objects from it.
BASIC PRINCIPLES OF OOP
There are four principles of Object-Oriented Programming (OOP) which are as follows:
Encapsulation Data Abstraction Inheritance Polymorphism
Let us learn about these in detail.
Encapsulation
Encapsulation refers to the bundling of data members and member methods into a single unit,
or class. This principle ensures that data can only be accessed through associated methods, thus
protecting it from outside interference and misuse. This concept is also known as data hiding.
A real-life example is a capsule. In general, a capsule is a small case or container, that protects
the medication inside from contamination by outside elements.
Data Abstraction
Data Abstraction is the principle of representing only the essential features of an object while
hiding non-essential details from the user.
For instance, when traveling in a car as a passenger, you are concerned only with reaching your
destination, not with how the driver operates the car by pressing the clutch, brake, and accelerator.
Inheritance
The procedure of generating a new class with the help of an already created class, by using
its properties and functionality is said to be inheritance. It is one of the important pillars of
Object-Oriented Programming. For example, in real world, a child inherits the properties (both
materialistic and non-materialistic) of its parents, who, in turn inherited them from their parents.
Polymorphism
The word Polymorphism comes from the Greek word meaning “many forms” ("poly" means
many and "morphe" means form). It is the ability of a variable, function, or object to take on
multiple forms. For example, the term "car" can refer to a family car, a taxi used by the general
public, or a pool car used by people.
INTRODUCING BLUEJ
Previously, simple text editors such as Notepad were used to
develop Java programs. With advancements in technology,
various Integrated Development Environments (IDE) are now
available, often free of cost. One such IDE is BlueJ.
Other examples of IDEs are Netbeans, and Eclipse. In this chapter,
BlueJ
we will talk about BlueJ.
Program Coding 51

