Abstraction java

2,397 views 7 slides Jul 11, 2020
Slide 1
Slide 1 of 7
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7

About This Presentation

Data abstraction is the process of hiding certain details and showing only essential information to the user.
Interfaces and Abstract classes.
Contains abstract keyword also.


Slide Content

ABSTRACTION

What is Abstraction ? There are four Pillars of OOP i.e. Polymorphism , Abstraction , Inheritance and Encapsulation. We’ll explore one of the four pillars of OOP i.e. Abstraction. Abstraction  is one of the key elements of good software design . In  java ,  abstraction  is achieved by interfaces and abstract classes. Abstraction is the art of hiding implementation details from the user and provide the user with what they want.

EXAMPLE OF ABSTRACTION Let’s try to understand abstraction further, with some  real-world examples. All are performing operations on the ATM machine like cash withdrawal, money transfer, retrieve mini-statement…etc. but we can't know internal details about ATM. ABSTRACTION 0-100% Abstract classes 100 % interface

Any class that contains one or more abstract methods must also be declared with abstract keyword . An abstract method is a method that is declared without an implementation . Abstract Method   can only be used in an abstract class, and it does not have a body . It can have constructors and static methods also. WHAT IS THE PURPOSE OF ABSTRACT CLASSES

INTERFACE IN JAVA The interface in Java is a mechanism to achieve  100 % abstraction. A class can extend only one class. An interface can extend another interface. But the class can implement more than one interface at a time . HOW ? For Example, the user who wants to use the methods of interface he only knows the classes that implement this interface, their methods. The information of implementation is completely hidden from the user.

Example : abstract class Car abstract void stop(); } class Civic extends Car{ void stop() { System.out.println("Civic Car is Stop on Signal"); } public static void main(String args[]){ Car obj = new Civic(); obj.stop(); } } SYNTAX : abstract void stop();

THANK YOU !