Index
Definition
Usefulness
Why they cannot be instantiated?
How to use abstract classes?
Purpose of abstract class
What is Concrete class?
Examples
Characteristics explained
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.
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.
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
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.
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.
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
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
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.
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)