0% found this document useful (0 votes)
2 views15 pages

9 Abstraction

The document covers key concepts of Object Oriented Programming, focusing on polymorphism, abstraction, and the use of abstract classes and methods in Java. It explains how abstraction hides implementation details and provides functionality, along with the rules for creating abstract classes and methods. Additionally, it outlines the importance of overriding methods in inheritance and the necessity of providing implementations for abstract methods in subclasses.

Uploaded by

kisafatymah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views15 pages

9 Abstraction

The document covers key concepts of Object Oriented Programming, focusing on polymorphism, abstraction, and the use of abstract classes and methods in Java. It explains how abstraction hides implementation details and provides functionality, along with the rules for creating abstract classes and methods. Additionally, it outlines the importance of overriding methods in inheritance and the necessity of providing implementations for abstract methods in subclasses.

Uploaded by

kisafatymah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Object Oriented

Programming
Topics To Be Covered Today
Polymorphism
◦ Method Overloading
◦ Method Overriding
◦ Run-time polymorphism
●Upcasting
◦ Polymorphism in multilevel inheritance
◦ Downcasting
Final keyword
Abstraction
◦ Abstract Class
◦ Abstract Method
Abstraction
A process of hiding the implementation details and
showing only functionality to the user.
it shows only important things to the user and
hides the internal details
◦ E.g. sending sms, you just type the text and send the
message. You don't know the internal processing about
the message delivery.

lets you focus on what the object does instead of


how it does it.
Ways to achieve Abstraction
There are two ways to achieve abstraction in java
◦ Abstract class
◦ Interface
Abstract Keyword:
The abstract keyword is a non-access modifier,
used for classes and methods:

Abstract class: is a restricted class that cannot be


used to create objects (to access it, it must be
inherited from another class).

Abstract method: can only be used in an abstract


class, and it does not have a body. The body is
provided by the subclass (inherited from).
An abstract class can have both abstract and
regular methods
Abstract class
A class that is declared with abstract keyword
Abstract Class:
◦ can have abstract and non-abstract methods (method
with body).
●if a class has at least one abstract method, then the
class must be declared abstract.
◦ cannot be instantiated.
◦ needs to be extended and its method implemented.

abstract class A{}


Example
Abstract Method
Inheritance allows a sub-class to override the
methods of its super-class.
In fact, a super-class may altogether leave the
implementation details of a method and declare
such a method abstract:
●abstract type name(parameter-list);
◦ Abstract methods – must be overridden by sub-
classes(to provide body)
It is illegal to define abstract constructors or static
methods.
Abstract Method
A method that is declared as abstract and does
not have implementation is known as abstract
method.
An abstract method
◦ contains a method signature, but no method body.
◦ Instead of curly braces, an abstract method will have a
semi colon (;) at the end.

abstract void printStatus();//


no body and abstract
Example
Another Example

Error??
Output??
class Bike {
abstract void run();
}

Rule:
◦ If there is any abstract method in a class, that class
must be abstract.
Rule:
If you are extending any abstract class that
have abstract method, you must either provide
the implementation of the method or make this
class abstract.
Questions?

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy