SlideShare a Scribd company logo
1 of 113
Download to read offline
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

9781439035665 ppt ch10
9781439035665 ppt ch109781439035665 ppt ch10
9781439035665 ppt ch10
Terry Yoast
 

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

Our Country India
Our Country IndiaOur Country India
Our Country India
guesta53677
 
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

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

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

Recently uploaded

Recently uploaded (20)

Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 

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)