The source code to create an abstract class without any abstract method is given below. The given program is compiled and executed successfully.
// Java program to create an abstract class
// without any abstract method
abstract class AbsClass {
void MyFun() {
System.out.println("MyFun() called");
}
}
class Sample extends AbsClass {
}
public class Main {
public static void main(String[] args) {
AbsClass abs = new Sample();
abs.MyFun();
}
}
Output:
MyFun() called
Explanation:
In the above program, we created an abstract class AbsClass with a non-abstract method. Then we will inherit the AbsClass into the Sample class.
The Main class contains a method main(). The main() method is the entry point for the program, here we created a reference of AbsClass and initialized it with the reference of Sample class. Then we called MyFun() method using the reference of AbsClass.
Program/Source Code:
The source code to create an abstract class without any abstract method is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we created an abstract class AbsClass with a non-abstract method. Then we will inherit the AbsClass into the Sample class.
The Main class contains a method main(). The main() method is the entry point for the program, here we created a reference of AbsClass and initialized it with the reference of Sample class. Then we called MyFun() method using the reference of AbsClass.
need an explanation for this answer? contact us directly to get an explanation for this answer