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

Corejavainterviewquestions.doc
Corejavainterviewquestions.docCorejavainterviewquestions.doc
Corejavainterviewquestions.doc
Joyce Thomas
 
9781439035665 ppt ch10
9781439035665 ppt ch109781439035665 ppt ch10
9781439035665 ppt ch10
Terry Yoast
 
Java căn bản - Chapter13
Java căn bản - Chapter13Java căn bản - Chapter13
Java căn bản - Chapter13
Vince Vo
 

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

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
deffa5
 
polymorphismpresentation-160825122725.pdf
polymorphismpresentation-160825122725.pdfpolymorphismpresentation-160825122725.pdf
polymorphismpresentation-160825122725.pdf
BapanKar2
 
abstract classes and interfaces in c++\ by M adnan Haider MNSUAM.pptx
abstract classes and interfaces in c++\ by M adnan Haider MNSUAM.pptxabstract classes and interfaces in c++\ by M adnan Haider MNSUAM.pptx
abstract classes and interfaces in c++\ by M adnan Haider MNSUAM.pptx
haiderkhooradnan
 

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
 
abstract classes and interfaces in c++\ by M adnan Haider MNSUAM.pptx
abstract classes and interfaces in c++\ by M adnan Haider MNSUAM.pptxabstract classes and interfaces in c++\ by M adnan Haider MNSUAM.pptx
abstract classes and interfaces in c++\ by M adnan Haider MNSUAM.pptx
 
Java interview questions
Java interview questionsJava interview questions
Java interview questions
 
Abstract Classes and Interfaces in oop.pptx
Abstract Classes and Interfaces in oop.pptxAbstract Classes and Interfaces in oop.pptx
Abstract Classes and Interfaces in oop.pptx
 
java tutorial 4
 java tutorial 4 java tutorial 4
java tutorial 4
 

Recently uploaded

Recently uploaded (20)

Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through Observability
 
ECS 2024 Teams Premium - Pretty Secure
ECS 2024   Teams Premium - Pretty SecureECS 2024   Teams Premium - Pretty Secure
ECS 2024 Teams Premium - Pretty Secure
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
 
Microsoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireMicrosoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - Questionnaire
 
A Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyA Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System Strategy
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties ReimaginedEasier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 

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.