SlideShare a Scribd company logo
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)

More Related Content

What's hot

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
Edureka!
 
Total oop in c# dot net
Total oop in c# dot netTotal oop in c# dot net
Total oop in c# dot net
Muhammad Naveed
 
Vvi
VviVvi
15 interfaces
15   interfaces15   interfaces
15 interfaces
dhrubo kayal
 
Unusual C# - OOP
Unusual C# - OOPUnusual C# - OOP
Unusual C# - OOP
Medhat Dawoud
 
Chap11
Chap11Chap11
Chap11
Terry Yoast
 
9781439035665 ppt ch10
9781439035665 ppt ch109781439035665 ppt ch10
9781439035665 ppt ch10
Terry Yoast
 
116824015 java-j2 ee
116824015 java-j2 ee116824015 java-j2 ee
116824015 java-j2 ee
homeworkping9
 
javainterface
javainterfacejavainterface
javainterface
Arjun Shanka
 
Java interfaces & abstract classes
Java interfaces & abstract classesJava interfaces & abstract classes
Java interfaces & abstract classes
Shreyans Pathak
 
Java Abstraction
Java AbstractionJava Abstraction
Java Abstraction
Soba Arjun
 
Lecture 10
Lecture 10Lecture 10
Lecture 10
Debasish Pratihari
 
Review oop and ood
Review oop and oodReview oop and ood
Review oop and ood
than sare
 
Chap04
Chap04Chap04
Chap04
Terry Yoast
 
C#, OOP introduction and examples
C#, OOP introduction and examplesC#, OOP introduction and examples
C#, OOP introduction and examples
agni_agbc
 
Basic design pattern interview questions
Basic design pattern interview questionsBasic design pattern interview questions
Basic design pattern interview questions
jinaldesailive
 
C# question answers
C# question answersC# question answers
C# question answers
application developer
 
06 abstract-classes
06 abstract-classes06 abstract-classes
06 abstract-classes
Abhishek Khune
 
OOP in C#
OOP in C#OOP in C#
OOP in C#
DevMix
 
ASE02 DMP.ppt
ASE02 DMP.pptASE02 DMP.ppt
ASE02 DMP.ppt
Ptidej Team
 

What's hot (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
 

Viewers also liked

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
Harish Gyanani
 
open source
open sourceopen source
open source
Harish Gyanani
 
Inline functions in c++
Inline functions in c++Inline functions in c++
Inline functions in c++
Harish Gyanani
 
Hardware concepts
Hardware conceptsHardware concepts
Hardware concepts
Harish Gyanani
 
What's database normalization
What's database normalizationWhat's database normalization
What's database normalization
Harish Gyanani
 
open source
open sourceopen source
open source
Harish Gyanani
 
Corruption In India
Corruption In IndiaCorruption In India
Corruption In India
Akshay Bharwani
 
Incredible India
Incredible IndiaIncredible India
Incredible India
Lisa Snyders
 
My country india
My country   indiaMy country   india
My country india
Ritisha Singh
 
Our Country India
Our Country IndiaOur Country India
Our Country India
guesta53677
 
Corruption in india
Corruption in indiaCorruption in india
Corruption in india
Dipu Thomas joy
 
Black Money in India.
Black Money in India.Black Money in India.
Black Money in India.
V'vek Sharma
 
Black money ppt
Black money pptBlack money ppt
Black money ppt
Sandeepika Sharma
 
INCREDIBLE INDIA
INCREDIBLE INDIAINCREDIBLE INDIA
INCREDIBLE INDIA
Biswajit Ghosh
 
Corruption ppt
Corruption pptCorruption ppt
Corruption ppt
Andini Nurul
 
India PPT
India PPTIndia PPT
India PPT
Piyush Gaur
 
Solar power.ppt
Solar power.pptSolar power.ppt
Solar power.ppt
Fauzia Samreen
 
Solar energy power point presentation
Solar energy power point presentation Solar energy power point presentation
Solar energy power point presentation
Shrijeet Modi
 
Solar energy ppt
Solar energy pptSolar energy ppt
Solar energy ppt
shubhajit_b
 

Viewers also liked (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
 

Similar to Abstract classes and Methods in java

Abstraction in java.pptx
Abstraction in java.pptxAbstraction in java.pptx
Abstraction in java.pptx
AsifMulani17
 
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 programming
deffa5
 
Java abstract Keyword.pdf
Java abstract Keyword.pdfJava abstract Keyword.pdf
Java abstract Keyword.pdf
SudhanshiBakre1
 
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
Ahmed Nobi
 
this keyword in Java.pdf
this keyword in Java.pdfthis keyword in Java.pdf
this keyword in Java.pdf
ParvizMirzayev2
 
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
Jamsher bhanbhro
 
Java 6.pptx
Java 6.pptxJava 6.pptx
Java 6.pptx
usmanusman720379
 
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
arihantkitchenmart
 
Micro Anti-patterns in Java Code
Micro Anti-patterns in Java CodeMicro Anti-patterns in Java Code
Micro Anti-patterns in Java Code
Ganesh Samarthyam
 
Java basics
Java basicsJava basics
Java basics
Shivanshu Purwar
 
Java interview
Java interviewJava interview
Java interview
Mohammad Shahban
 
Java Core Parctical
Java Core ParcticalJava Core Parctical
Java Core Parctical
Gaurav Mehta
 
Java Unit 2(part 3)
Java Unit 2(part 3)Java Unit 2(part 3)
Java Unit 2(part 3)
SURBHI SAROHA
 
Core java notes with examples
Core java notes with examplesCore java notes with examples
Core java notes with examples
bindur87
 
More oop in java
More oop in javaMore oop in java
More oop in java
SAGARDAVE29
 
Oop
OopOop
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
haiderkhooradnan
 
Core java by amit
Core java by amitCore java by amit
Core java by amit
Thakur Amit Tomer
 
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 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
 
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
 
Core java by amit
Core java by amitCore java by amit
Core java by amit
 
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
 

Recently uploaded

The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
paigestewart1632
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5
sayalidalavi006
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 

Recently uploaded (20)

The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 

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)