SlideShare a Scribd company logo
1 of 13
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
Thank You

More Related Content

What's hot

What's hot (20)

06 abstract-classes
06 abstract-classes06 abstract-classes
06 abstract-classes
 
Chapter 9 Abstract Class
Chapter 9 Abstract ClassChapter 9 Abstract Class
Chapter 9 Abstract Class
 
9 abstract interface
9 abstract interface9 abstract interface
9 abstract interface
 
Lecture 18
Lecture 18Lecture 18
Lecture 18
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
 
Abstract method
Abstract methodAbstract method
Abstract method
 
Abstract classes
Abstract classesAbstract classes
Abstract classes
 
Abstract class
Abstract classAbstract class
Abstract class
 
Corejavainterviewquestions.doc
Corejavainterviewquestions.docCorejavainterviewquestions.doc
Corejavainterviewquestions.doc
 
Chapter 13 - Inheritance and Polymorphism
Chapter 13 - Inheritance and PolymorphismChapter 13 - Inheritance and Polymorphism
Chapter 13 - Inheritance and Polymorphism
 
Exception Handling in C#
Exception Handling in C#Exception Handling in C#
Exception Handling in C#
 
Java assignment help
Java assignment helpJava assignment help
Java assignment help
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Chap04
Chap04Chap04
Chap04
 
9781439035665 ppt ch10
9781439035665 ppt ch109781439035665 ppt ch10
9781439035665 ppt ch10
 
Chap11
Chap11Chap11
Chap11
 
15 interfaces
15   interfaces15   interfaces
15 interfaces
 
Java căn bản - Chapter13
Java căn bản - Chapter13Java căn bản - Chapter13
Java căn bản - Chapter13
 
Abstract classes and Methods in java
Abstract classes and Methods in javaAbstract classes and Methods in java
Abstract classes and Methods in java
 
Abstract class
Abstract classAbstract class
Abstract class
 

Similar to Abstract_descrption

Exception handling and packages.pdf
Exception handling and packages.pdfException handling and packages.pdf
Exception handling and packages.pdfKp Sharma
 
Abstraction in Java: Abstract class and Interfaces
Abstraction in  Java: Abstract class and InterfacesAbstraction in  Java: Abstract class and Interfaces
Abstraction in Java: Abstract class and InterfacesJamsher bhanbhro
 
Java interfaces & abstract classes
Java interfaces & abstract classesJava interfaces & abstract classes
Java interfaces & abstract classesShreyans Pathak
 
06_OOVP.pptx object oriented and visual programming
06_OOVP.pptx object oriented and visual programming06_OOVP.pptx object oriented and visual programming
06_OOVP.pptx object oriented and visual programmingdeffa5
 
Core java notes with examples
Core java notes with examplesCore java notes with examples
Core java notes with examplesbindur87
 
ABSTRACT CLASSES AND INTERFACES.ppt
ABSTRACT CLASSES AND INTERFACES.pptABSTRACT CLASSES AND INTERFACES.ppt
ABSTRACT CLASSES AND INTERFACES.pptJayanthiM15
 
Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...
Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...
Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...Akhil Mittal
 
Polymorphism presentation in java
Polymorphism presentation in javaPolymorphism presentation in java
Polymorphism presentation in javaAhsan Raja
 
polymorphismpresentation-160825122725.pdf
polymorphismpresentation-160825122725.pdfpolymorphismpresentation-160825122725.pdf
polymorphismpresentation-160825122725.pdfBapanKar2
 
Java abstract Keyword.pdf
Java abstract Keyword.pdfJava abstract Keyword.pdf
Java abstract Keyword.pdfSudhanshiBakre1
 
abstract,final,interface (1).pptx upload
abstract,final,interface (1).pptx uploadabstract,final,interface (1).pptx upload
abstract,final,interface (1).pptx uploaddashpayal697
 
Abstraction in java.pptx
Abstraction in java.pptxAbstraction in java.pptx
Abstraction in java.pptxAsifMulani17
 
Master of Computer Application (MCA) – Semester 4 MC0078
Master of Computer Application (MCA) – Semester 4  MC0078Master of Computer Application (MCA) – Semester 4  MC0078
Master of Computer Application (MCA) – Semester 4 MC0078Aravind NC
 

Similar to Abstract_descrption (20)

Exception handling and packages.pdf
Exception handling and packages.pdfException handling and packages.pdf
Exception handling and packages.pdf
 
Abstraction in Java: Abstract class and Interfaces
Abstraction in  Java: Abstract class and InterfacesAbstraction in  Java: Abstract class and Interfaces
Abstraction in Java: Abstract class and Interfaces
 
Java interfaces & abstract classes
Java interfaces & abstract classesJava interfaces & abstract classes
Java interfaces & abstract classes
 
06_OOVP.pptx object oriented and visual programming
06_OOVP.pptx object oriented and visual programming06_OOVP.pptx object oriented and visual programming
06_OOVP.pptx object oriented and visual programming
 
Core java notes with examples
Core java notes with examplesCore java notes with examples
Core java notes with examples
 
ABSTRACT CLASSES AND INTERFACES.ppt
ABSTRACT CLASSES AND INTERFACES.pptABSTRACT CLASSES AND INTERFACES.ppt
ABSTRACT CLASSES AND INTERFACES.ppt
 
Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...
Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...
Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...
 
Polymorphism presentation in java
Polymorphism presentation in javaPolymorphism presentation in java
Polymorphism presentation in java
 
polymorphismpresentation-160825122725.pdf
polymorphismpresentation-160825122725.pdfpolymorphismpresentation-160825122725.pdf
polymorphismpresentation-160825122725.pdf
 
Java abstract Keyword.pdf
Java abstract Keyword.pdfJava abstract Keyword.pdf
Java abstract Keyword.pdf
 
Java basics
Java basicsJava basics
Java basics
 
abstract,final,interface (1).pptx upload
abstract,final,interface (1).pptx uploadabstract,final,interface (1).pptx upload
abstract,final,interface (1).pptx upload
 
Java 06
Java 06Java 06
Java 06
 
Java Unit 2(part 3)
Java Unit 2(part 3)Java Unit 2(part 3)
Java Unit 2(part 3)
 
Oop
OopOop
Oop
 
Abstraction in java.pptx
Abstraction in java.pptxAbstraction in java.pptx
Abstraction in java.pptx
 
Java interview questions
Java interview questionsJava interview questions
Java interview questions
 
java tutorial 4
 java tutorial 4 java tutorial 4
java tutorial 4
 
Unit 4 notes.pdf
Unit 4 notes.pdfUnit 4 notes.pdf
Unit 4 notes.pdf
 
Master of Computer Application (MCA) – Semester 4 MC0078
Master of Computer Application (MCA) – Semester 4  MC0078Master of Computer Application (MCA) – Semester 4  MC0078
Master of Computer Application (MCA) – Semester 4 MC0078
 

Recently uploaded

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfOverkill Security
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 

Recently uploaded (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 

Abstract_descrption

  • 1. Miracle Software Systems, Inc. Abstract Class and methods By Mahehs pappala, Application Developer, Miracle Software Systems,Inc. Email:mpappplai@miraclesoft.com
  • 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
  • 12.