Abstract Method
Author: Ravi Poswal
Only the abstract class may define it, and a parent class may declare the implementation. Suppose you want to declare an abstract method. So It must place the “abstract” keyword before the method name.
-
It contains the method signature but not the method body.
-
All abstract methods must declare on subclasses.
-
It must be declared in an abstract class.
Code Example
abstract class Teacher {
abstract void teach();
void student() {
System.out.println("He is student.");
}
}
class College extends Teacher {
void teach() {
System.out.println("he is part of scholar");
}
}
public class Main
{
public static void main(String[] args)
{
Teacher my = new College();
my.teach();
my.student();
}
}
RANREV INFOTECH