Monday, May 9, 2011

Published 5/09/2011 by with 1 comment

illegal combination of modifiers: abstract and static

An abstract method cannot be static because the abstract method must be overridden i.e, body of the abstract method must be defined before invocation.

See the wrong code below:

public abstract class Employee
{
public static abstract double earnings(); // error
}

Here the abstract method earnings() is declared as static. An abstract method must be non-static. So the correct code is:


public abstract class Employee
{
public abstract double earnings(); // no error now
}


    email this       edit

1 comment:

  1. I don't want to be belittling your post, but this is too mundane even for Java 101 class. All the information expressed here is already in the compiler error message. You should be aiming for posts more useful than that.

    ReplyDelete