SlideShare a Scribd company logo
Miracle Software Systems, Inc.
Abstract Class and methods
By
Mahehs pappala,
Application Developer,
Miracle Software Systems,Inc.
Email:mpappplai@miraclesoft.com
2
Abstract classes
An abstract class is a class that is declared as abstract.
abstract class MyClass {...}
An abstract class may or may not include abstract methods.
Abstract classes cannot be instantiate(crate a new instance of),
but it can be used for inheritance only.
Whenever a class extends an abstract class then the class should
compulsorily override all the abstract methods of super class.
abstract class common
{
abstract void accept();
abstract void display();
}
Class student extends common
{
Void accept()
{}
}
Class student extends common
{
Void accept()
{ }
Void dispaly()
{}
}
Example of Abstract classes
4
Abstract classes
You can declare a class to be abstract even if it does not contain any
abstract methods
This prevents the class from being instantiated.
Any class that extends the abstract class has to provide the
implementation to the abstract methods.
Abstract Methods
you can declare a method without defining it:
public abstract void draw(int size);
Notice that the body of the method is missing
A method that has been declared but not defined is an abstract
method
6
Why have abstract classes?
Suppose you wanted to create a class Shape, with subclasses Oval,
Rectangle, Triangle, Hexagon, etc.
You don’t want to allow creation of a “Shape”

Only particular shapes make sense, not generic ones

If Shape is abstract, you can’t create a new Shape

You can create a new Oval, a new Rectangle, etc.
Abstract classes are good for defining a general category containing
specific, “concrete” classes
7
An example abstract class
public abstract class Animal {
abstract int eat();
abstract void breathe();
}
This class cannot be instantiated
Any non-abstract subclass of Animal must provide the eat() and
breathe() methods
8
Why have abstract methods?
Separate interface from implementation.
What we are trying to achieve in object-oriented programming.
Allows programmers to isolate type specific details from the main part of the
code.
Client programs only use the method provided by the Shape class in the
shape hierarchy example.
Code is simpler to write and to read.
Can change types (and add new types) with this propagates to existing code.
9
A problem
class Shape { ... }
class Star extends Shape {
void draw() { ... }
...
}
class Crescent extends Shape {
void draw() { ... }
...
}
Shape someShape = new Star();
This is legal, because a Star is a Shape
someShape.draw();
This is a syntax error, because some Shape might not have a draw() method
Remember: A class knows its superclass, but not its subclasses
10
A solution
abstract class Shape {
abstract void draw();
}
class Star extends Shape {
void draw() { ... }
...
}
class Crescent extends Shape {
void draw() { ... }
...
}
Shape someShape = new Star();
This is legal, because a Star is a Shape
However, Shape someShape = new Shape(); is no longer legal
someShape.draw();
This is legal, because every actual instance must have a draw() method
References
Abstract_descrption
Thank You

More Related Content

PPT
06 abstract-classes
Anup Burange
 
PPTX
Interfaces and abstract classes
AKANSH SINGHAL
 
PPT
Abstract class in java
Lovely Professional University
 
PDF
What are Abstract Classes in Java | Edureka
Edureka!
 
PDF
Abstract classes and interfaces
Sérgio Souza Costa
 
PPTX
Abstract Class & Abstract Method in Core Java
MOHIT AGARWAL
 
PPTX
Abstraction in java [abstract classes and Interfaces
Ahmed Nobi
 
PPT
Java Programming - Abstract Class and Interface
Oum Saokosal
 
06 abstract-classes
Anup Burange
 
Interfaces and abstract classes
AKANSH SINGHAL
 
Abstract class in java
Lovely Professional University
 
What are Abstract Classes in Java | Edureka
Edureka!
 
Abstract classes and interfaces
Sérgio Souza Costa
 
Abstract Class & Abstract Method in Core Java
MOHIT AGARWAL
 
Abstraction in java [abstract classes and Interfaces
Ahmed Nobi
 
Java Programming - Abstract Class and Interface
Oum Saokosal
 

What's hot (20)

PPT
06 abstract-classes
Abhishek Khune
 
PPT
Chapter 9 Abstract Class
OUM SAOKOSAL
 
PPT
9 abstract interface
Abhijit Gaikwad
 
PPTX
Lecture 18
talha ijaz
 
PPTX
Java abstract class & abstract methods
Shubham Dwivedi
 
PPTX
Abstract method
Yaswanth Babu Gummadivelli
 
PPT
Abstract classes
Ruchika Dhiman
 
PPT
Abstract class
Hoang Nguyen
 
DOCX
Corejavainterviewquestions.doc
Joyce Thomas
 
PPT
Chapter 13 - Inheritance and Polymorphism
Eduardo Bergavera
 
PPTX
Exception Handling in C#
Abid Kohistani
 
PPTX
Java assignment help
Jacob William
 
PPTX
Java interfaces
jehan1987
 
PPT
Chap04
Terry Yoast
 
PPT
9781439035665 ppt ch10
Terry Yoast
 
PPT
Chap11
Terry Yoast
 
PPTX
15 interfaces
dhrubo kayal
 
PPT
Java căn bản - Chapter13
Vince Vo
 
PDF
Abstract classes and Methods in java
Harish Gyanani
 
PPTX
Abstract class
PhD Research Scholar
 
06 abstract-classes
Abhishek Khune
 
Chapter 9 Abstract Class
OUM SAOKOSAL
 
9 abstract interface
Abhijit Gaikwad
 
Lecture 18
talha ijaz
 
Java abstract class & abstract methods
Shubham Dwivedi
 
Abstract classes
Ruchika Dhiman
 
Abstract class
Hoang Nguyen
 
Corejavainterviewquestions.doc
Joyce Thomas
 
Chapter 13 - Inheritance and Polymorphism
Eduardo Bergavera
 
Exception Handling in C#
Abid Kohistani
 
Java assignment help
Jacob William
 
Java interfaces
jehan1987
 
Chap04
Terry Yoast
 
9781439035665 ppt ch10
Terry Yoast
 
Chap11
Terry Yoast
 
15 interfaces
dhrubo kayal
 
Java căn bản - Chapter13
Vince Vo
 
Abstract classes and Methods in java
Harish Gyanani
 
Abstract class
PhD Research Scholar
 
Ad

Similar to Abstract_descrption (20)

PDF
Exception handling and packages.pdf
Kp Sharma
 
PDF
Abstraction in Java: Abstract class and Interfaces
Jamsher bhanbhro
 
PPT
Java interfaces & abstract classes
Shreyans Pathak
 
PPTX
06_OOVP.pptx object oriented and visual programming
deffa5
 
DOCX
Core java notes with examples
bindur87
 
PPT
ABSTRACT CLASSES AND INTERFACES.ppt
JayanthiM15
 
PDF
Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...
Akhil Mittal
 
PPTX
Abstraction encapsulation inheritance polymorphism
PriyadharshiniG41
 
PDF
How to Work with Java Interfaces and Abstract Classes
Naresh IT
 
PPTX
Polymorphism presentation in java
Ahsan Raja
 
PDF
polymorphismpresentation-160825122725.pdf
BapanKar2
 
PPTX
Abstract classes.pptx Abstract classesAbstract classesAbstract classes
yatakonakiran2
 
PDF
Java abstract Keyword.pdf
SudhanshiBakre1
 
PPTX
Java basics
Shivanshu Purwar
 
PPTX
abstract,final,interface (1).pptx upload
dashpayal697
 
PDF
Java Abstract and Final Class for BCA students
Jainul Musani
 
PDF
Java 06
Loida Igama
 
PPTX
Java Unit 2(part 3)
Dr. SURBHI SAROHA
 
PPTX
Inheritance & interface ppt Inheritance
narikamalliy
 
Exception handling and packages.pdf
Kp Sharma
 
Abstraction in Java: Abstract class and Interfaces
Jamsher bhanbhro
 
Java interfaces & abstract classes
Shreyans Pathak
 
06_OOVP.pptx object oriented and visual programming
deffa5
 
Core java notes with examples
bindur87
 
ABSTRACT CLASSES AND INTERFACES.ppt
JayanthiM15
 
Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...
Akhil Mittal
 
Abstraction encapsulation inheritance polymorphism
PriyadharshiniG41
 
How to Work with Java Interfaces and Abstract Classes
Naresh IT
 
Polymorphism presentation in java
Ahsan Raja
 
polymorphismpresentation-160825122725.pdf
BapanKar2
 
Abstract classes.pptx Abstract classesAbstract classesAbstract classes
yatakonakiran2
 
Java abstract Keyword.pdf
SudhanshiBakre1
 
Java basics
Shivanshu Purwar
 
abstract,final,interface (1).pptx upload
dashpayal697
 
Java Abstract and Final Class for BCA students
Jainul Musani
 
Java 06
Loida Igama
 
Java Unit 2(part 3)
Dr. SURBHI SAROHA
 
Inheritance & interface ppt Inheritance
narikamalliy
 
Ad

Recently uploaded (20)

PDF
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
PDF
The Future of Artificial Intelligence (AI)
Mukul
 
PDF
Doc9.....................................
SofiaCollazos
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PDF
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
The Future of Artificial Intelligence (AI)
Mukul
 
Doc9.....................................
SofiaCollazos
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 

Abstract_descrption

  • 1. Miracle Software Systems, Inc. Abstract Class and methods By Mahehs pappala, Application Developer, Miracle Software Systems,Inc. Email:[email protected]
  • 2. 2 Abstract classes An abstract class is a class that is declared as abstract. abstract class MyClass {...} An abstract class may or may not include abstract methods. Abstract classes cannot be instantiate(crate a new instance of), but it can be used for inheritance only. Whenever a class extends an abstract class then the class should compulsorily override all the abstract methods of super class.
  • 3. abstract class common { abstract void accept(); abstract void display(); } Class student extends common { Void accept() {} } Class student extends common { Void accept() { } Void dispaly() {} } Example of Abstract classes
  • 4. 4 Abstract classes You can declare a class to be abstract even if it does not contain any abstract methods This prevents the class from being instantiated. Any class that extends the abstract class has to provide the implementation to the abstract methods.
  • 5. Abstract Methods you can declare a method without defining it: public abstract void draw(int size); Notice that the body of the method is missing A method that has been declared but not defined is an abstract method
  • 6. 6 Why have abstract classes? Suppose you wanted to create a class Shape, with subclasses Oval, Rectangle, Triangle, Hexagon, etc. You don’t want to allow creation of a “Shape”  Only particular shapes make sense, not generic ones  If Shape is abstract, you can’t create a new Shape  You can create a new Oval, a new Rectangle, etc. Abstract classes are good for defining a general category containing specific, “concrete” classes
  • 7. 7 An example abstract class public abstract class Animal { abstract int eat(); abstract void breathe(); } This class cannot be instantiated Any non-abstract subclass of Animal must provide the eat() and breathe() methods
  • 8. 8 Why have abstract methods? Separate interface from implementation. What we are trying to achieve in object-oriented programming. Allows programmers to isolate type specific details from the main part of the code. Client programs only use the method provided by the Shape class in the shape hierarchy example. Code is simpler to write and to read. Can change types (and add new types) with this propagates to existing code.
  • 9. 9 A problem class Shape { ... } class Star extends Shape { void draw() { ... } ... } class Crescent extends Shape { void draw() { ... } ... } Shape someShape = new Star(); This is legal, because a Star is a Shape someShape.draw(); This is a syntax error, because some Shape might not have a draw() method Remember: A class knows its superclass, but not its subclasses
  • 10. 10 A solution abstract class Shape { abstract void draw(); } class Star extends Shape { void draw() { ... } ... } class Crescent extends Shape { void draw() { ... } ... } Shape someShape = new Star(); This is legal, because a Star is a Shape However, Shape someShape = new Shape(); is no longer legal someShape.draw(); This is legal, because every actual instance must have a draw() method