
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
Static method in Interface in Java
To implement static method in Interface, the Java code is as follows −
Example
interface my_interface{ static void static_fun(){ System.out.println("In the newly created static method"); } void method_override(String str); } public class Demo_interface implements my_interface{ public static void main(String[] args){ Demo_interface demo_inter = new Demo_interface(); my_interface.static_fun(); demo_inter.method_override("In the override method"); } @Override public void method_override(String str){ System.out.println(str); } }
Output
In the newly created static method In the override method
An interface is defined, inside which a static function is defined. Another function named ‘method_override’ is defined without a body. This interface is implemented by another class named ‘Demo_interface’. Inside this class, the main function is defined, and an instance of this ‘Demo_interface’ is also created. The static function is called on this instance, and next, the ‘method_override’ function is called on this instance. An override specification is written, under which the ‘method_override’ is defined. This function just prints the string on the console.
- Related Articles
- Default method vs static method in an interface in Java?
- Difference between default and static interface method in Java 8.
- Why can't we define a static method in a Java interface?
- Can we have a private method or private static method in an interface in Java 9?\n
- Java static method
- Can we create non static variables in an interface using java?
- Interface variables are static and final by default in Java, Why?
- Are values returned by static method are static in java?
- How to call an interface method in Java?
- Can we override the static method in Java?
- Why main() method must be static in java?
- How to call a non-static method of an abstract class from a static method in java?
- Why the main () method in Java is always static?
- Static vs. Non-Static method in C#
- Can we use "this" keyword in a static method in java?

Advertisements