Java program to create a simple interface
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
total answers (1)
In this program, we will create an interface with an abstract method. Then we will implement created interface into a class using the "implements" keyword.
Program/Source Code:
The source code to create a simple interface is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we created an interface Inf with an abstract method sayHello(). Then we defined the sayHello() method in the Main class by implementing the Inf interface using the "implements" keyword.
The Main class contains a method main() and defined sayHello() method. The main() method is the entry point for the program, here we created the object of the Main class and called sayHello() method, and printed the result.