Shandan Spencer
Shandan Spencer

Reputation: 113

The method must override or implement a superclass method

Quick question. I am using Eclipse and I am getting the The method must override or implement a superclass method error, except Eclipse is using compliance of Java 1.7.
Here is my Code:

public abstract class M4 implements Armory {

@Override
public Integer weaponAmmo(int wepAmmo) {
    wepAmmo = 10;
    return wepAmmo;
}

@Override
public Integer weaponDamage(int wepDamage) {
    wepDamage = 2;
    return wepDamage;
}

@Override
public String weaponName(String wepName) {
    wepName = "M4";
    return wepName;
}

And here is the interface Code:

public interface Armory {
        public Integer weaponAmmo(int wepAmmo);
        public Integer weaponDamage(int wepDamage);
        public String weaponName(String wepName);

    }

Any Ideas?

Upvotes: 4

Views: 15681

Answers (4)

Ankit Shah
Ankit Shah

Reputation: 31

Even if Eclipse has been set to compliance level higher than Java 1.5 this error may occur because of Project properties as in your case. Right click on your Project > Properties > Java Compiler. Change it to 1.6 or higher here too. Do Project > Clean.

Upvotes: 0

Subin Sebastian
Subin Sebastian

Reputation: 10997

You are not overriding anything, you are implementing them . So i guess @Override can be removed.

EDIT: I think your compiler is set to Java 1.5 in eclipse

Why does Eclipse complain about @Override on interface methods?

@override on interface implementations are allowed from java 1.6 onwards.

Upvotes: 1

Evgeniy Dorofeev
Evgeniy Dorofeev

Reputation: 136062

In Java 5 @Override was allowed only for methods overriding super class methods. Since Java 6 @Override is also allowed for methods implementing interface methods.

Upvotes: 2

Yogendra Singh
Yogendra Singh

Reputation: 34387

You don't need to use @override annotation in your method implementation as you are not overriding the methods. You are just implementing the interface methods. This annotation is required when your override any super class methods.

Remove the @Override annotations and it should be fine.

Upvotes: 6

Related Questions