Sie sind auf Seite 1von 11

Abstraction is a technique of dealing with the complexity of an

object . It means focusing only on the essential details and


overlooking the not-essential details of an object.

For Example : Dr.Smith want to sent a medical report of a


patient to Birmingham very urgently. She hands over the report
to a well known courier company-carrier and gives them the
same and address of the receiver. After three days, Dr.Smith
gets an acknowledgment receipt which is duly singed by her
patient. She is happy that the report has reached the
destination in three days. In this process of sending the report,
Dr.Smith need not know how the courier company has. Sent
the report. She is not even concerned with their packing
process or their travelling means. For her, the important thing
is that her job is done. This concept of ignoring the
unimportant data and concentrating only on the important
Hands over Report

Hands over
Acknowledgement
receipt
Dr.Smith
Report is packed
And sealed

Gets
Acknowledgments
Receipt signed

Report sent to
destination
Lesson Overview
 Abstract keyword
 Abstract method
 Abstract classes
When a method has only declaration and no
implementation, that is , no statements in the body,
then it is called an abstract.

An abstract method in java is prefixed with the


abstract keyword. An abstract method is only a
contract that the subclass will provide its
implementation.

An abstract method does not specify any


implementation. The method declaration. The
method declaration does not contain any braces and is
terminated by a semicolon.
Public abstract void DraftMemo();

Here, DraftMemo() is an abstract method As can be seen,


The abstract keyword is used declare the method abstract.
The method declaration is terminated with a semicolon.

 Abstract method
 Abstract keyword
 No method body
 Declaration terminates with semi-
colon
A class may be required to serve as framework that provides
certain behavior for other classes. A subclasses provides
their application or requirement- specific behavior that adds
to the behavior of the existing framework. Such as
framework is crated by using the abstract keyword.

abstract class <class name >


{
[ abstract <method return type>
<methodname>(); ]
}
A class may be required to serve as framework that provides
certain behavior for other classes. A subclasses provides
their application or requirement- specific behavior that adds
to the behavior Framework
of the existing framework.
for other classes Such as
framework is crated
Zero by using the abstract
or more abstract keyword.
methods
Cannot be instantiated
abstract class<class
Can bename >
inherited
{
[ abstract <method return type>
<methodname>(); ]
}
Abstract class OutlinePerposal
{
public abstract void DraftMemo();
}
public void claccosts()
{
System.out.println(“Coasts”);
}
}
In the example, "Outline Proposal” is an abstract class. It
defines a framework for other classes deriving from it to
follow.
DraftMemo() is an abstract method declared in the class.
Outline proposal. The implementation of this method varies
for each subclass derived from the class outlineproposal.
abstract class Shape
{
abstract void area();
}
class Square extends Shape
{
int side;
void area()
{
System.out.println("Area ="+side*side);
}

public static void main(String args[])


{
Square obj=new Square();
obj.side=10;
obj.area();
}
}
abstract class Shape
{
abstract public void Draw();
}
Class AbstractDemo
class Rectangle extends Shape
{ {
public void Draw()
{
Public static void main(String args[])
{
System.out.println("Drawing a Rectangle");
} Shape s=new Rectangle();
} s.Draw();
s=new Circle();
class Circle extends Shape
{
s.Draw();
public void Draw()
{ }
} System.out.println("Drawing a Circle");
Output:
} Drawing a Rectangle
} Drawing a Circle

continued….

Das könnte Ihnen auch gefallen