Abstraction in Java: Abstract Classes and Methods
Abstraction in Java: Abstract Classes and Methods
Abstraction in Java
Abstract classes and methods
A method with without body (no implementation) is known as abstract method. A method must always
be declared in an abstract class, or in other words you can say that if a class has an abstract method, it
should be declared abstract as well.
Points to Remember
• Abstract classes are not Interfaces. They are different, we will study this when we will study
Interfaces.
• An abstract class may or may not have an abstract method. But if any class has even a single
abstract method, then it must be declared abstract.
• Abstract classes can have Constructors, Member variables and Normal methods.
• Abstract classes are never instantiated.
• When you extend Abstract class with abstract method, you must define the abstract method in
the child class, or make the child class abstract.
1
TT@GU
EMP132-Java Programming-Basic
Example of abstract class that has abstract method
In this example, Bike the abstract class that contains only one abstract method run. It implementation is
provided by the Honda class.
Important Points
• Abstract class having constructor, data member, methods etc.
• If there is any abstract method in a class, that class must be abstract.
• If you are extending any abstract class that have abstract method, you must either provide the
implementation of the method or make this class abstract.
2
TT@GU