Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 4

Abstract Method

● Abstract method: can only be used in an abstract class, and it


does not have a body. The body is provided by the subclass
(inherited from).
● Abstract methods are the methods with no body or
implementation, it will only have its declaration ends with
semicolon and starts with abstract keyword.
● Abstract methods will be resides in abstract class or interfaces.
Abstract class
● Abstract class: is a restricted class that cannot be used to create objects (to
access it, it must be inherited from another class).
● A class which is declared with the abstract keyword is known as
an abstract class in Java. It can have abstract and non-abstract
methods (method with the body).
● Abstract class will use as superclasses for other classes, they can
not be instantiated.
When we inherit Bike class
the run() method should
Abstract class example implement with in that
otherwise the class will be
again abstract
abstract class Bike{
abstract void run();
}
class Honda4 extends Bike{
void run(){
Bike is the abstract class.
In the class run() is the
System.out.println("running safely");
abstract method without }
implementation
public static void main(String args[]){
Bike obj = new Honda4();
obj.run();
}
}

You might also like