Java throwing error “ is not abstract and does not override abstract method in the

前端 未结 3 811
小鲜肉
小鲜肉 2020-12-12 03:10

I am unable to compile the below code written, Java always throws an error. Can you please help me out (P.S: I am new to Java, in a learning stage still). If anywhere, i hav

3条回答
  •  无人及你
    2020-12-12 03:28

    You probably want to read up a little on interfaces. They are one of the strongest aspects of Java and object-oriented design in general.

    If you create an interface called "calci," you are creating a contract that any class implementing the interface will implement what you defined in calci. So you may want to rethink how this is designed currently.

    To describe how it works, change the interface to only have one method called "perform." Now, in the implementing classes addition, subtraction, multiplication, and division, create a method also called "perform." You can call it almost anything other than "perform," but make it a characteristic that you feel all classes that calci implements or other interfaces that extend calci should guarantee.

    Then it will be possible to do:

    calci addition = new addition();
    addition.perform();
    
    calci multiplication = new multiplication();
    multiplication.perform();
    

    etc.

    You can use the @Override annotation on the implementing method to make sure that misspellings are caught in your IDE (like Eclipse).

提交回复
热议问题