How to Override a Static Method in Java
Overriding a static class method in Java involves the use of inheritance. If you create an inherited class that contains the same method name as the parent class, the parent class method is ignored and you override its function with the child class function. You must create a new class that inherits another and create a method with the same name as the parent to override in Java.
Instructions
-
-
1
Right-click the Java file you want to use to override the method and click "Open With." Click the Java editor of your choice, such as Eclipse or the Oracle Java editor.
-
2
Create the inherited class. The following code inherits the class "Car":
public class Engine extends Car {
} -
-
3
Override the parent class method. For instance, if the parent class has a method named "Start," you create a "Start" method in your inherited class. The following code overrides the "Start" method in the "Engine" class created earlier:
public static void Start() {
System.out.println("The overridden Start method");
}
-
1