Home »
Java »
Java Programs
Java program to create an abstract class with a static method
Learn how to create an abstract class with a static method in Java?
Submitted by Nidhi, on March 27, 2022
Problem statement
In this program, we will create an abstract class with a static method. Then we will inherit the abstract class into another class.
Java program to create an abstract class with a static method
The source code to create an abstract class with a static method is given below. The given program is compiled and executed successfully.
// Java program to create an abstract class
// with a static method
abstract class AbsClass {
static void MyFun() {
System.out.println("MyFun() called");
}
}
public class Main extends AbsClass {
public static void main(String[] args) {
AbsClass.MyFun();
}
}
Output
MyFun() called
Explanation
In the above program, we created an abstract class AbsClass with a static method MyFun(). Then we will inherit the AbsClass into the Main class.
The Main class contains a method main(). The main() method is the entry point for the program, here we called MyFun() method using the AbsClass and printed the result.
Java Abstract Class Programs »