Abstract Static Method Java


Abstract Static Method looks odd as it cannot exist in Java and declaring so, compiler will not keep quiet. Discussed with Example, Screenshot in Simple terms in Question/Answer format for a Beginner.

1. Can we declare Abstract Static Method?

Before answering this question, let us brief about abstract methods.

Following points are to be remembered with abstract methods.

1. First of all, an abstract method cannot be static as static methods should have a body and abstract methods should not.

2. An abstract class can have the following combinations of methods.

  1. All methods abstract
  2. All methods concrete (non-abstract)
  3. A mixture of abstract and non-abstract methods

Observe, it the above list Abstract Static Method does not exist.

Now we have a different question to be answered.

2. Can an abstract class have static methods?

Yes, definitely can have as a static method is special flavor of concrete method. We know a static method can be called with object name (not possible here), class name and directly without the help of an object. Following program explains.

abstract class Test
{
  public static void display()
  {
    System.out.println("Hello 1");
  }
}
public class Demo extends Test
{
  public static void main(String args[]) 
  {
    display();
    Test.display();
  }
}


In the above code, the display() method is declared static. It is called in the subclass directly and with abstract class name.

Now another confusing question is to be answered.

3. Can an interface have static methods?

No, impossible. A person having a little knowledge of interfaces can answer.

All methods of an interface must be public and abstract (by default takes also if not mentioned). As static methods should have a body, the interface methods cannot be static.

More on abstract classes and interfaces.

1. Extends Implements
2. Getting objects of Interfaces – Through Object Casing
3. Java Constructor Properties
4. Abstract class constructor & Interface abstract
5. Why the methods of an interface should be overridden as public only?

5 thoughts on “Abstract Static Method Java”

  1. interface can have static methods. Try this code for instance
    public interface Hello {

    static void display() {
    System.out.println(“Static display”);
    }

    }

Leave a Comment

Your email address will not be published.