0% found this document useful (0 votes)
19 views4 pages

Abstract Method and Classes

Abstract methods are methods declared in an abstract class without a body and must be implemented by subclasses. Abstract classes cannot be instantiated and are intended to be subclassed, allowing subclasses to determine the implementation of abstract methods. For example, an abstract Bike class declares an abstract run() method, requiring subclasses like Honda4 to provide a run implementation or also be abstract.

Uploaded by

midhunchelakkara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views4 pages

Abstract Method and Classes

Abstract methods are methods declared in an abstract class without a body and must be implemented by subclasses. Abstract classes cannot be instantiated and are intended to be subclassed, allowing subclasses to determine the implementation of abstract methods. For example, an abstract Bike class declares an abstract run() method, requiring subclasses like Honda4 to provide a run implementation or also be abstract.

Uploaded by

midhunchelakkara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 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