Page 133 - Computer science 868 Class 12
P. 133
In object-oriented programming, the key purpose of abstraction is to hide the details that are not required from the
users. Abstraction is like a query passed to a database that extracts the required data only leaving the rest. The main
purpose is to reduce the programming complexity. It is one of the most important concepts of OOPs.
As, we can see in the example given under encapsulation, the data members and the methods are all hidden from
outside methods within the same project as well as different projects. So, here applies the concept of Data Abstraction.
Definition
Data Abstraction is the property by which the essential features are represented without knowing the background
details that how it is actually executing, i.e., non-essential units are hidden from the user.
4.4.3 Inheritance
The procedure of generating a new class with the help of a class already created by using its properties and functionality
is said to be inheritance. Thus, it is the feature of acquiring the feature of other classes by another class that reduces
the coding size. It is one of the important pillars of object-oriented programming.
Inheritance in Java is the method to create a hierarchy between classes by inheriting attributes from other classes. It
supports the concept of reusability where some portion of the program code can be used multiple times so that the
program code can be reduced.
The most appropriate example of inheritance is parents and child. Each child inherits the properties of parents along
with its own properties.
Definition
Inheritance in Java is the method which allows one class to inherit the properties (data members and
member methods) of another class.
Let us see the programming implementation of inheritance with the help of the following example:
class shape
{ int length;
int breadth;
shape(int l, int b)
{
length = l;
breadth = b;
}
}
class rectangle extends shape
{ int area;
rectangle(int l, int b)
{
super(l,b);
}
void calculate()
{
area = length * breadth;
}
void display()
{
System.out.println("Area of Rectangle "+area);
}
131
Programming in Java 131

