Abstraction in Java

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 7

ABSTRACTION IN

JAVA
INTRODUCTION

 It is one of the 5 major pillar of OOPS CONCEPT.


 It is the process of hiding details and showing only
essential information to user.
 It can be achieved by using interface and abstract
class in java.
ABSTRACT CLASSES AND METHOD

 Abstraction refers to the act of representing


essential features without including the
background details or explanations. since the
classes use the concept of data abstraction ,they are
known as abstraction data type(ADT)
REAL LIFE EXAMPLE
 When you drive your car you do not have to be concerned
with the exact internal working of your car(unless you are
a mechanic). What you are concerned with is interacting
with your car via its interfaces like steering wheel, brake
pedal, accelerator pedal etc. Various manufacturers of car
has different implementation of car working but its basic
interface has not changed (i.e. you still use steering wheel,
brake pedal, accelerator pedal etc to interact with your
car). Hence the knowledge you have of your car is
abstract.
EXAMPLES OF ABSTRACT CLASS
1. abstract class Car{  
2.   abstract void run();  
3. }  
4. class Honda extends Car{  
5. void run(){System.out.println("running safely");}  
6. public static void main(String args[]){  
7.  Car obj = new Honda();  
8.  obj.run();  
9. }  
10.}  
POINTS TO REMEMBER

• An abstract class must be declared with an abstract


keyword.
• It can have abstract and non-abstract methods.
• It cannot be instantiated.
• It can have constructor and static methods also.
• It can have final methods which will force the
subclass not to change the body of the method.
ABSTRACT METHOD IN JAVA

 Abstract Method in Java


 A method which is declared as abstract and does
not have implementation is known as an abstract
method.
 Example of abstract method
Abstract void printStatus();  

You might also like