SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (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
 

Ähnlich wie Abstract Class Methods Explained

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
 

Ähnlich wie Abstract Class Methods Explained (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
 

Kürzlich hochgeladen

New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 

Kürzlich hochgeladen (20)

New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 

Abstract Class Methods Explained

  • 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.