SlideShare une entreprise Scribd logo
1  sur  113
Télécharger pour lire hors ligne
Abstract classes and Methods in
Java
A Presentation in Depth
Index
Definition
Usefulness
Why they cannot be instantiated?
How to use abstract classes?
Purpose of abstract class
What is Concrete class?
Examples
Characteristics explained
Definition
Abstract classes—for which you never intend to
create objects.
Useful
They’re used only as superclasses in inheritance
hierarchies, we refer to them as abstract
superclasses.
Why they cannot be instantiated?
1. These classes cannot be used to instantiate
objects, because abstract classes are
incomplete.
2. Abstract superclasses are too general to
create real objects—they specify only what is
common among subclasses.
So how can we use them? Or
instantiate them?
Subclasses must declare the “missing pieces” to
become “concrete” classes, from which you can
instantiate objects.
What is the purpose of abstract class?
An abstract class’s purpose is to provide an
appropriate superclass from which other classes
can inherit and thus share a common design.
What is concrete class?
Classes that can be used to instantiate objects
are called concrete classes. Such classes provide
implementations of every method they declare
(some of the implementations can be inherited).
Concrete classes provide the specifics that make
it reasonable to instantiate objects.
Example 1
Example 2
Characteristics summary
Characteristics summary
1. Abstract class can be empty.
Characteristics summary
1. Abstract class can be empty.
2. Abstract class can be made without abstract
methods.
Characteristics summary
1. Abstract class can be empty.
2. Abstract class can be made without abstract
methods.
3. A non-abstract class cannot contain abstract
method.
Abstract class can be empty
Abstract class can be empty
abstract class Vehicle{}
Abstract class can be empty
abstract class Vehicle{}

Contains no
members
Abstract class can be empty
abstract class Vehicle{}

Perfectly valid

Contains no
members
Abstract class can be made without
abstract methods
Abstract class can be made without
abstract methods
abstract class Vehicle
{
void brake()
{
System.out.println("non abstract method brake");

}
}
Abstract class can be made without
abstract methods
abstract class Vehicle
{
void brake()
{
System.out.println("non abstract method brake");

}
}
Non abstract
method
Abstract class can be made without
abstract methods
abstract class Vehicle
{
void brake()
{
System.out.println("non abstract method brake");

}
}
Non abstract
method

Perfectly
valid
class Vehicle
{
abstract void brake();
}
class Vehicle
{
abstract void brake();
}

Invalid/compilation
error
A non-abstract class cannot contain
abstract method
class Vehicle
{
abstract void brake();
}

Invalid/compilation
error
A non-abstract class cannot contain
abstract method
class Vehicle
{
abstract void brake();
}

Invalid/compilation
error

In other words, if
a class contains
abstract method
then class must
also be abstract.
A non-abstract class cannot contain
abstract method
class Vehicle
{
abstract void brake();
}

Invalid/compilation
error

Now valid

abstract class Vehicle
{
abstract void brake();
}

In other words, if
a class contains
abstract method
then class must
also be abstract.
Example 3
Example 4
Characteristics summary
Characteristics summary
4. Class can be final or abstract, not both.
Characteristics summary
4. Class can be final or abstract, not both.
5. Method be can be final or abstract not both.
Class can be abstract or final, not both
Class can be abstract or final, not both

Error
Method can be abstract or final, not
both
Method can be abstract or final, not
both

Error
Real Examples of Abstract Classes in
Java API
1. java.awt.Component
Component

Button

Checkbox

Label

TextComponent
Real Examples of Abstract Classes in
Java API
2. java.lang.Number

Number

Byte

Long

Integer

Float

Double
Real Examples of Abstract Classes in
Java API
3. javax.swing.AbstractButton
AbstractButton

JButton

JToggleButton

JMenuItem
Characteristics summary
Characteristics summary
6. Non-abstract class cannot contain abstract methods even
there are non abstract methods too.
Characteristics summary
6. Non-abstract class cannot contain abstract methods even
there are non abstract methods too.
7. An abstract class can contain both abstract and non abstract
methods.
Characteristics summary
6. Non-abstract class cannot contain abstract methods even
there are non abstract methods too.
7. An abstract class can contain both abstract and non abstract
methods.
8. Abstract class can be inherited like normal class.
Characteristics summary
6. Non-abstract class cannot contain abstract methods even
there are non abstract methods too.
7. An abstract class can contain both abstract and non abstract
methods.
8. Abstract class can be inherited like normal class.
9. If abstract class contains no abstract methods then subclass
of it, can be empty.
Non-abstract class cannot contain abstract
methods even there are non-abstract methods
too
Non-abstract class cannot contain abstract
methods even there are non-abstract methods
too

Non abstract
method
Non-abstract class cannot contain abstract
methods even there are non-abstract methods
too
Abstract
method

Non abstract
method
Non-abstract class cannot contain abstract
methods even there are non-abstract methods
too
Abstract
method

Non abstract
method

Either make the class
abstract or make method
non abstract to correct
this error
An abstract class can contain both
abstract and non abstract methods
An abstract class can contain both
abstract and non abstract methods

Non
abstract
method
An abstract class can contain both
abstract and non abstract methods
Abstract
method

Non
abstract
method
Abstract class can be inherited like
normal class

If abstract class
is empty then
subclass can
also be empty.
Abstract class can be inherited like
normal class

If abstract class
is empty then
subclass can
also be empty.
Abstract class can be inherited like
normal class

No error

If abstract class
is empty then
subclass can
also be empty.
If abstract class contains no abstract
methods then subclass of it, can be empty
If abstract class contains no abstract
methods then subclass of it, can be empty
If abstract class contains no abstract
methods then subclass of it, can be empty

Perfectly
valid
Example 5
Example 6
Example 7
Characteristics summary
Characteristics summary
10. If abstract class contains one or more abstract methods
then subclass of it, can not be empty.
Characteristics summary
10. If abstract class contains one or more abstract methods
then subclass of it, can not be empty.
11. If abstract class contains one or more abstract methods
then subclass of it, can be empty, only if subclass is also
abstract.
Characteristics summary
10. If abstract class contains one or more abstract methods
then subclass of it, can not be empty.
11. If abstract class contains one or more abstract methods
then subclass of it, can be empty, only if subclass is also
abstract.
12. If a abstract class contains abstract methods then subclass
must have to implements(write code) for abstract
methods, if subclass does not want to be abstract.
If abstract class contains one or more abstract
methods then subclass of it, can not be empty
If abstract class contains one or more abstract
methods then subclass of it, can not be empty
If abstract class contains one or more abstract
methods then subclass of it, can not be empty

Error
If abstract class contains one or more abstract
methods then subclass of it, can not be empty

Error
If abstract class contains one or more abstract
methods then subclass of it, can not be empty

Error

There are two ways to correct
this error either implement
abstract methods in subclass or
make subclass abstract.
If abstract class contains one or more abstract
methods then subclass of it, can not be empty

Error

There are two ways to correct
this error either implement
abstract methods in subclass or
make subclass abstract.

Next slides
will show
how to
remove this
error
If abstract class contains one or more abstract
methods then subclass of it, can be empty, only
if subclass is also abstract
If abstract class contains one or more abstract
methods then subclass of it, can be empty, only
if subclass is also abstract
If abstract class contains one or more abstract
methods then subclass of it, can be empty, only
if subclass is also abstract

Perfectly
valid
If a abstract class contains abstract methods then subclass must
have to implements(write code) for abstract methods, if subclass
does not want to be abstract
If a abstract class contains abstract methods then subclass must
have to implements(write code) for abstract methods, if subclass
does not want to be abstract

Perfectly
valid
Characteristics summary
Characteristics summary
13.Abstract class can implement super class
abstract methods.
Characteristics summary
13.Abstract class can implement super class
abstract methods.
14.Abstract classes can contain final methods,
constructors, static methods.
Characteristics summary
13.Abstract class can implement super class
abstract methods.
14.Abstract classes can contain final methods,
constructors, static methods.
15.An abstract class cannot be instantiated, but we
can make reference of this class.
If abstract class contains one or more abstract
methods then subclass of it, can be abstract and still
can implements super class methods.
If abstract class contains one or more abstract
methods then subclass of it, can be abstract and still
can implements super class methods.
If abstract class contains one or more abstract
methods then subclass of it, can be abstract and still
can implements super class methods. Abstract

super class
If abstract class contains one or more abstract
methods then subclass of it, can be abstract and still
can implements super class methods. Abstract

super class

Abstract
sub class
If abstract class contains one or more abstract
methods then subclass of it, can be abstract and still
can implements super class methods. Abstract

super class

Abstract
sub class

In other words,
abstract class can
implement super
class abstract
methods
If abstract class contains one or more abstract
methods then subclass of it, can be abstract and still
can implements super class methods. Abstract

super class

Abstract
sub class

Perfectly
valid

In other words,
abstract class can
implement super
class abstract
methods
Abstract classes can contain
constructors
Abstract classes can contain static
methods
Abstract classes can contain static
methods
Abstract classes can contain static
methods
Abstract classes can contain static
methods

Output
Abstract classes can contain final
methods
Abstract classes can contain final
methods

Perfectly
valid
An abstract class cannot be
instantiated
An abstract class cannot be
instantiated
We can make reference of
abstract class
An abstract class cannot be
instantiated
We can make reference of
abstract class

Error
Example 8
Example 9
Characteristics summary
8. Abstract methods cannot be private. They
can have public, protected or default access
specifier.
9. Abstract class can extend non-abstract class.
Abstract methods cannot be private
Abstract methods cannot be private

Error
Abstract methods can use public
access specifier
Abstract methods can use protected
access specifier
Abstract methods can use default
access specifier
Abstract class can inherit non-abstract
class
Abstract class can inherit non-abstract
class

Perfectly
valid
Complete Characteristics summary
1.
2.
3.
4.
5.
6.
7.

Abstract class can be empty.(slide 2)
Abstract class can be made without abstract methods. (slide 3)
A non-abstract class cannot contain abstract method.(slide 4)
Non-abstract class cannot contain abstract methods even there
are non abstract methods too.(slide 5)
An abstract class can contain both abstract and non abstract
methods.(slide 6)
Abstract class can be inherited like normal class(slide 7)
If abstract class contains no abstract methods then subclass of it,
can be empty(slide 8)
Complete Characteristics summary
8.
9.
10.
11.
12.
13.
14.
15.

If abstract class contains one or more abstract methods then subclass of
it, can not be empty(slide 9)
If abstract class contains one or more abstract methods then subclass of
it, can be empty, only if subclass is also abstract(slide 10)
If a abstract class contains abstract methods then subclass must have to
implements(write code) for abstract methods, if subclass does not want
to be abstract(slide 11)
Abstract class can implement super class abstract methods. (slide 12)
Abstract classes can contain final methods, constructors, static
methods.(slide 13,14,15)
An abstract class cannot be instantiated, but we can make reference of
this class.(slide 16)
Abstract methods cannot be private. They can have public, protected or
default access specifier.(slide 17,18,19,20)
Abstract class can extend non-abstract class.(slide 21)
Complete Characteristics summary
17.Class can be final or abstract, not both.(slide
22)
18.Method be can be final or abstract not
both.(slide 23)

Contenu connexe

Tendances

What are Abstract Classes in Java | Edureka
What are Abstract Classes in Java | EdurekaWhat are Abstract Classes in Java | Edureka
What are Abstract Classes in Java | EdurekaEdureka!
 
9781439035665 ppt ch10
9781439035665 ppt ch109781439035665 ppt ch10
9781439035665 ppt ch10Terry Yoast
 
116824015 java-j2 ee
116824015 java-j2 ee116824015 java-j2 ee
116824015 java-j2 eehomeworkping9
 
Java interfaces & abstract classes
Java interfaces & abstract classesJava interfaces & abstract classes
Java interfaces & abstract classesShreyans Pathak
 
Java Abstraction
Java AbstractionJava Abstraction
Java AbstractionSoba Arjun
 
Review oop and ood
Review oop and oodReview oop and ood
Review oop and oodthan sare
 
C#, OOP introduction and examples
C#, OOP introduction and examplesC#, OOP introduction and examples
C#, OOP introduction and examplesagni_agbc
 
Basic design pattern interview questions
Basic design pattern interview questionsBasic design pattern interview questions
Basic design pattern interview questionsjinaldesailive
 
OOP in C#
OOP in C#OOP in C#
OOP in C#DevMix
 

Tendances (20)

What are Abstract Classes in Java | Edureka
What are Abstract Classes in Java | EdurekaWhat are Abstract Classes in Java | Edureka
What are Abstract Classes in Java | Edureka
 
Total oop in c# dot net
Total oop in c# dot netTotal oop in c# dot net
Total oop in c# dot net
 
Vvi
VviVvi
Vvi
 
15 interfaces
15   interfaces15   interfaces
15 interfaces
 
Unusual C# - OOP
Unusual C# - OOPUnusual C# - OOP
Unusual C# - OOP
 
Chap11
Chap11Chap11
Chap11
 
9781439035665 ppt ch10
9781439035665 ppt ch109781439035665 ppt ch10
9781439035665 ppt ch10
 
116824015 java-j2 ee
116824015 java-j2 ee116824015 java-j2 ee
116824015 java-j2 ee
 
javainterface
javainterfacejavainterface
javainterface
 
Java interfaces & abstract classes
Java interfaces & abstract classesJava interfaces & abstract classes
Java interfaces & abstract classes
 
Java Abstraction
Java AbstractionJava Abstraction
Java Abstraction
 
Lecture 10
Lecture 10Lecture 10
Lecture 10
 
Review oop and ood
Review oop and oodReview oop and ood
Review oop and ood
 
Chap04
Chap04Chap04
Chap04
 
C#, OOP introduction and examples
C#, OOP introduction and examplesC#, OOP introduction and examples
C#, OOP introduction and examples
 
Basic design pattern interview questions
Basic design pattern interview questionsBasic design pattern interview questions
Basic design pattern interview questions
 
C# question answers
C# question answersC# question answers
C# question answers
 
06 abstract-classes
06 abstract-classes06 abstract-classes
06 abstract-classes
 
OOP in C#
OOP in C#OOP in C#
OOP in C#
 
ASE02 DMP.ppt
ASE02 DMP.pptASE02 DMP.ppt
ASE02 DMP.ppt
 

En vedette (19)

Simple class and object examples in java
Simple class and object examples in javaSimple class and object examples in java
Simple class and object examples in java
 
open source
open sourceopen source
open source
 
Inline functions in c++
Inline functions in c++Inline functions in c++
Inline functions in c++
 
Hardware concepts
Hardware conceptsHardware concepts
Hardware concepts
 
What's database normalization
What's database normalizationWhat's database normalization
What's database normalization
 
open source
open sourceopen source
open source
 
Corruption In India
Corruption In IndiaCorruption In India
Corruption In India
 
Incredible India
Incredible IndiaIncredible India
Incredible India
 
My country india
My country   indiaMy country   india
My country india
 
Our Country India
Our Country IndiaOur Country India
Our Country India
 
Corruption in india
Corruption in indiaCorruption in india
Corruption in india
 
Black Money in India.
Black Money in India.Black Money in India.
Black Money in India.
 
Black money ppt
Black money pptBlack money ppt
Black money ppt
 
INCREDIBLE INDIA
INCREDIBLE INDIAINCREDIBLE INDIA
INCREDIBLE INDIA
 
Corruption ppt
Corruption pptCorruption ppt
Corruption ppt
 
India PPT
India PPTIndia PPT
India PPT
 
Solar power.ppt
Solar power.pptSolar power.ppt
Solar power.ppt
 
Solar energy power point presentation
Solar energy power point presentation Solar energy power point presentation
Solar energy power point presentation
 
Solar energy ppt
Solar energy pptSolar energy ppt
Solar energy ppt
 

Similaire à Abstract classes and Methods in java

Abstraction in java.pptx
Abstraction in java.pptxAbstraction in java.pptx
Abstraction in java.pptxAsifMulani17
 
When to use abstract class and methods in java
When to use abstract class and methods in java When to use abstract class and methods in java
When to use abstract class and methods in java kritikumar16
 
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
 
Java abstract Keyword.pdf
Java abstract Keyword.pdfJava abstract Keyword.pdf
Java abstract Keyword.pdfSudhanshiBakre1
 
Abstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and InterfacesAbstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and InterfacesAhmed Nobi
 
this keyword in Java.pdf
this keyword in Java.pdfthis keyword in Java.pdf
this keyword in Java.pdfParvizMirzayev2
 
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
 
What are abstract classes Dont interfaces also allow for polymo.pdf
What are abstract classes Dont interfaces also allow for polymo.pdfWhat are abstract classes Dont interfaces also allow for polymo.pdf
What are abstract classes Dont interfaces also allow for polymo.pdfarihantkitchenmart
 
Micro Anti-patterns in Java Code
Micro Anti-patterns in Java CodeMicro Anti-patterns in Java Code
Micro Anti-patterns in Java CodeGanesh Samarthyam
 
Java Core Parctical
Java Core ParcticalJava Core Parctical
Java Core ParcticalGaurav Mehta
 
Core java notes with examples
Core java notes with examplesCore java notes with examples
Core java notes with examplesbindur87
 
More oop in java
More oop in javaMore oop in java
More oop in javaSAGARDAVE29
 
Java/J2EE interview Qestions
Java/J2EE interview QestionsJava/J2EE interview Qestions
Java/J2EE interview QestionsArun Vasanth
 

Similaire à Abstract classes and Methods in java (20)

Abstraction in java.pptx
Abstraction in java.pptxAbstraction in java.pptx
Abstraction in java.pptx
 
When to use abstract class and methods in java
When to use abstract class and methods in java When to use abstract class and methods in java
When to use abstract class and methods in java
 
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
 
Java abstract Keyword.pdf
Java abstract Keyword.pdfJava abstract Keyword.pdf
Java abstract Keyword.pdf
 
Abstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and InterfacesAbstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and Interfaces
 
this keyword in Java.pdf
this keyword in Java.pdfthis keyword in Java.pdf
this keyword in Java.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 6.pptx
Java 6.pptxJava 6.pptx
Java 6.pptx
 
What are abstract classes Dont interfaces also allow for polymo.pdf
What are abstract classes Dont interfaces also allow for polymo.pdfWhat are abstract classes Dont interfaces also allow for polymo.pdf
What are abstract classes Dont interfaces also allow for polymo.pdf
 
Micro Anti-patterns in Java Code
Micro Anti-patterns in Java CodeMicro Anti-patterns in Java Code
Micro Anti-patterns in Java Code
 
Java basics
Java basicsJava basics
Java basics
 
Java interview
Java interviewJava interview
Java interview
 
Java Core Parctical
Java Core ParcticalJava Core Parctical
Java Core Parctical
 
Java Unit 2(part 3)
Java Unit 2(part 3)Java Unit 2(part 3)
Java Unit 2(part 3)
 
Core java notes with examples
Core java notes with examplesCore java notes with examples
Core java notes with examples
 
More oop in java
More oop in javaMore oop in java
More oop in java
 
Oop
OopOop
Oop
 
Core java by amit
Core java by amitCore java by amit
Core java by amit
 
Java/J2EE interview Qestions
Java/J2EE interview QestionsJava/J2EE interview Qestions
Java/J2EE interview Qestions
 
OOPS ABAP.docx
OOPS ABAP.docxOOPS ABAP.docx
OOPS ABAP.docx
 

Dernier

CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 

Dernier (20)

CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 

Abstract classes and Methods in java

  • 1. Abstract classes and Methods in Java A Presentation in Depth
  • 2. Index Definition Usefulness Why they cannot be instantiated? How to use abstract classes? Purpose of abstract class What is Concrete class? Examples Characteristics explained
  • 3. Definition Abstract classes—for which you never intend to create objects.
  • 4. Useful They’re used only as superclasses in inheritance hierarchies, we refer to them as abstract superclasses.
  • 5. Why they cannot be instantiated? 1. These classes cannot be used to instantiate objects, because abstract classes are incomplete. 2. Abstract superclasses are too general to create real objects—they specify only what is common among subclasses.
  • 6. So how can we use them? Or instantiate them? Subclasses must declare the “missing pieces” to become “concrete” classes, from which you can instantiate objects.
  • 7. What is the purpose of abstract class? An abstract class’s purpose is to provide an appropriate superclass from which other classes can inherit and thus share a common design.
  • 8. What is concrete class? Classes that can be used to instantiate objects are called concrete classes. Such classes provide implementations of every method they declare (some of the implementations can be inherited). Concrete classes provide the specifics that make it reasonable to instantiate objects.
  • 12. Characteristics summary 1. Abstract class can be empty.
  • 13. Characteristics summary 1. Abstract class can be empty. 2. Abstract class can be made without abstract methods.
  • 14. Characteristics summary 1. Abstract class can be empty. 2. Abstract class can be made without abstract methods. 3. A non-abstract class cannot contain abstract method.
  • 15.
  • 16. Abstract class can be empty
  • 17. Abstract class can be empty abstract class Vehicle{}
  • 18. Abstract class can be empty abstract class Vehicle{} Contains no members
  • 19. Abstract class can be empty abstract class Vehicle{} Perfectly valid Contains no members
  • 20.
  • 21. Abstract class can be made without abstract methods
  • 22. Abstract class can be made without abstract methods abstract class Vehicle { void brake() { System.out.println("non abstract method brake"); } }
  • 23. Abstract class can be made without abstract methods abstract class Vehicle { void brake() { System.out.println("non abstract method brake"); } } Non abstract method
  • 24. Abstract class can be made without abstract methods abstract class Vehicle { void brake() { System.out.println("non abstract method brake"); } } Non abstract method Perfectly valid
  • 25.
  • 27. class Vehicle { abstract void brake(); } Invalid/compilation error
  • 28. A non-abstract class cannot contain abstract method class Vehicle { abstract void brake(); } Invalid/compilation error
  • 29. A non-abstract class cannot contain abstract method class Vehicle { abstract void brake(); } Invalid/compilation error In other words, if a class contains abstract method then class must also be abstract.
  • 30. A non-abstract class cannot contain abstract method class Vehicle { abstract void brake(); } Invalid/compilation error Now valid abstract class Vehicle { abstract void brake(); } In other words, if a class contains abstract method then class must also be abstract.
  • 34. Characteristics summary 4. Class can be final or abstract, not both.
  • 35. Characteristics summary 4. Class can be final or abstract, not both. 5. Method be can be final or abstract not both.
  • 36. Class can be abstract or final, not both
  • 37. Class can be abstract or final, not both Error
  • 38. Method can be abstract or final, not both
  • 39. Method can be abstract or final, not both Error
  • 40. Real Examples of Abstract Classes in Java API 1. java.awt.Component Component Button Checkbox Label TextComponent
  • 41. Real Examples of Abstract Classes in Java API 2. java.lang.Number Number Byte Long Integer Float Double
  • 42. Real Examples of Abstract Classes in Java API 3. javax.swing.AbstractButton AbstractButton JButton JToggleButton JMenuItem
  • 44. Characteristics summary 6. Non-abstract class cannot contain abstract methods even there are non abstract methods too.
  • 45. Characteristics summary 6. Non-abstract class cannot contain abstract methods even there are non abstract methods too. 7. An abstract class can contain both abstract and non abstract methods.
  • 46. Characteristics summary 6. Non-abstract class cannot contain abstract methods even there are non abstract methods too. 7. An abstract class can contain both abstract and non abstract methods. 8. Abstract class can be inherited like normal class.
  • 47. Characteristics summary 6. Non-abstract class cannot contain abstract methods even there are non abstract methods too. 7. An abstract class can contain both abstract and non abstract methods. 8. Abstract class can be inherited like normal class. 9. If abstract class contains no abstract methods then subclass of it, can be empty.
  • 48. Non-abstract class cannot contain abstract methods even there are non-abstract methods too
  • 49. Non-abstract class cannot contain abstract methods even there are non-abstract methods too Non abstract method
  • 50. Non-abstract class cannot contain abstract methods even there are non-abstract methods too Abstract method Non abstract method
  • 51. Non-abstract class cannot contain abstract methods even there are non-abstract methods too Abstract method Non abstract method Either make the class abstract or make method non abstract to correct this error
  • 52.
  • 53.
  • 54. An abstract class can contain both abstract and non abstract methods
  • 55. An abstract class can contain both abstract and non abstract methods Non abstract method
  • 56. An abstract class can contain both abstract and non abstract methods Abstract method Non abstract method
  • 57. Abstract class can be inherited like normal class If abstract class is empty then subclass can also be empty.
  • 58. Abstract class can be inherited like normal class If abstract class is empty then subclass can also be empty.
  • 59. Abstract class can be inherited like normal class No error If abstract class is empty then subclass can also be empty.
  • 60. If abstract class contains no abstract methods then subclass of it, can be empty
  • 61. If abstract class contains no abstract methods then subclass of it, can be empty
  • 62. If abstract class contains no abstract methods then subclass of it, can be empty Perfectly valid
  • 67. Characteristics summary 10. If abstract class contains one or more abstract methods then subclass of it, can not be empty.
  • 68. Characteristics summary 10. If abstract class contains one or more abstract methods then subclass of it, can not be empty. 11. If abstract class contains one or more abstract methods then subclass of it, can be empty, only if subclass is also abstract.
  • 69. Characteristics summary 10. If abstract class contains one or more abstract methods then subclass of it, can not be empty. 11. If abstract class contains one or more abstract methods then subclass of it, can be empty, only if subclass is also abstract. 12. If a abstract class contains abstract methods then subclass must have to implements(write code) for abstract methods, if subclass does not want to be abstract.
  • 70. If abstract class contains one or more abstract methods then subclass of it, can not be empty
  • 71. If abstract class contains one or more abstract methods then subclass of it, can not be empty
  • 72. If abstract class contains one or more abstract methods then subclass of it, can not be empty Error
  • 73. If abstract class contains one or more abstract methods then subclass of it, can not be empty Error
  • 74. If abstract class contains one or more abstract methods then subclass of it, can not be empty Error There are two ways to correct this error either implement abstract methods in subclass or make subclass abstract.
  • 75. If abstract class contains one or more abstract methods then subclass of it, can not be empty Error There are two ways to correct this error either implement abstract methods in subclass or make subclass abstract. Next slides will show how to remove this error
  • 76. If abstract class contains one or more abstract methods then subclass of it, can be empty, only if subclass is also abstract
  • 77. If abstract class contains one or more abstract methods then subclass of it, can be empty, only if subclass is also abstract
  • 78. If abstract class contains one or more abstract methods then subclass of it, can be empty, only if subclass is also abstract Perfectly valid
  • 79. If a abstract class contains abstract methods then subclass must have to implements(write code) for abstract methods, if subclass does not want to be abstract
  • 80. If a abstract class contains abstract methods then subclass must have to implements(write code) for abstract methods, if subclass does not want to be abstract Perfectly valid
  • 82. Characteristics summary 13.Abstract class can implement super class abstract methods.
  • 83. Characteristics summary 13.Abstract class can implement super class abstract methods. 14.Abstract classes can contain final methods, constructors, static methods.
  • 84. Characteristics summary 13.Abstract class can implement super class abstract methods. 14.Abstract classes can contain final methods, constructors, static methods. 15.An abstract class cannot be instantiated, but we can make reference of this class.
  • 85. If abstract class contains one or more abstract methods then subclass of it, can be abstract and still can implements super class methods.
  • 86. If abstract class contains one or more abstract methods then subclass of it, can be abstract and still can implements super class methods.
  • 87. If abstract class contains one or more abstract methods then subclass of it, can be abstract and still can implements super class methods. Abstract super class
  • 88. If abstract class contains one or more abstract methods then subclass of it, can be abstract and still can implements super class methods. Abstract super class Abstract sub class
  • 89. If abstract class contains one or more abstract methods then subclass of it, can be abstract and still can implements super class methods. Abstract super class Abstract sub class In other words, abstract class can implement super class abstract methods
  • 90. If abstract class contains one or more abstract methods then subclass of it, can be abstract and still can implements super class methods. Abstract super class Abstract sub class Perfectly valid In other words, abstract class can implement super class abstract methods
  • 91. Abstract classes can contain constructors
  • 92. Abstract classes can contain static methods
  • 93. Abstract classes can contain static methods
  • 94. Abstract classes can contain static methods
  • 95. Abstract classes can contain static methods Output
  • 96. Abstract classes can contain final methods
  • 97. Abstract classes can contain final methods Perfectly valid
  • 98. An abstract class cannot be instantiated
  • 99. An abstract class cannot be instantiated We can make reference of abstract class
  • 100. An abstract class cannot be instantiated We can make reference of abstract class Error
  • 103. Characteristics summary 8. Abstract methods cannot be private. They can have public, protected or default access specifier. 9. Abstract class can extend non-abstract class.
  • 104. Abstract methods cannot be private
  • 105. Abstract methods cannot be private Error
  • 106. Abstract methods can use public access specifier
  • 107. Abstract methods can use protected access specifier
  • 108. Abstract methods can use default access specifier
  • 109. Abstract class can inherit non-abstract class
  • 110. Abstract class can inherit non-abstract class Perfectly valid
  • 111. Complete Characteristics summary 1. 2. 3. 4. 5. 6. 7. Abstract class can be empty.(slide 2) Abstract class can be made without abstract methods. (slide 3) A non-abstract class cannot contain abstract method.(slide 4) Non-abstract class cannot contain abstract methods even there are non abstract methods too.(slide 5) An abstract class can contain both abstract and non abstract methods.(slide 6) Abstract class can be inherited like normal class(slide 7) If abstract class contains no abstract methods then subclass of it, can be empty(slide 8)
  • 112. Complete Characteristics summary 8. 9. 10. 11. 12. 13. 14. 15. If abstract class contains one or more abstract methods then subclass of it, can not be empty(slide 9) If abstract class contains one or more abstract methods then subclass of it, can be empty, only if subclass is also abstract(slide 10) If a abstract class contains abstract methods then subclass must have to implements(write code) for abstract methods, if subclass does not want to be abstract(slide 11) Abstract class can implement super class abstract methods. (slide 12) Abstract classes can contain final methods, constructors, static methods.(slide 13,14,15) An abstract class cannot be instantiated, but we can make reference of this class.(slide 16) Abstract methods cannot be private. They can have public, protected or default access specifier.(slide 17,18,19,20) Abstract class can extend non-abstract class.(slide 21)
  • 113. Complete Characteristics summary 17.Class can be final or abstract, not both.(slide 22) 18.Method be can be final or abstract not both.(slide 23)