Java抛出错误 "<Class Name> is not abstract and does not override abstract method in the <Interface>"

标签 java

我无法编译下面编写的代码,Java 总是抛出错误。你能帮我一下吗(P.S:我是Java新手,仍处于学习阶段)。如果我的代码有写错的地方,请帮我改正,以便我能学好。

抛出错误 (4): 1.加法不是抽象的,不会重写calci中的抽象方法Div()

  1. 减法不是抽象的,不会重写 calci 中的抽象方法 Div()

  2. 除法不是抽象的,不会重写 calci 中的抽象方法 Div()

  3. 乘法不是抽象的,不会覆盖 calci 中的抽象方法 Div()

    import java.util.Scanner;
    
    interface calci    
    
    {
    
    
        void add();
        void sub();
        void mul();
        void div();
    }
    

添加类

class addition implements calci   

{

public void add()    

    {
        System.out.println("Enter two numbers:");
        Scanner scn = new Scanner(System.in);
        int n = scn.nextInt();
        int n1= scn.nextInt();
        int result = n+n1;
        System.out.println("The Result of the two numbers is:"+result);
    }
}

类别减法

class subtraction implements calci

{

    public void sub()`enter code here`
    {
        System.out.println("Enter two numbers:");
        Scanner scn = new Scanner(System.in);
        int n = scn.nextInt();
        int n1= scn.nextInt();
        int result = n-n1;
        System.out.println("The Result of the two numbers is:"+result);
    }
}

类乘法

class multiplication implements calci

{

    public void mul()
    {
        System.out.println("Enter two numbers:");
        Scanner scn = new Scanner(System.in);
        int n = scn.nextInt();
        int n1= scn.nextInt();
        int result = n*n1;
        System.out.println("The Result of the two numbers is:"+result);
    }
}

类(class)划分

class division implements calci

{

    public void div()
    {
        System.out.println("Enter two numbers:");
        Scanner scn = new Scanner(System.in);
        int n = scn.nextInt();
        int n1= scn.nextInt();
        int result = n/n1;
        System.out.println("The Result of the two numbers is:"+result);
    }
}

类计算器1

class calculator1

{

    public static void main(String[] args)
    {
        int i =0;
        addition a1 = new addition();
        subtraction s1 = new subtraction();
        multiplication m1 = new multiplication();
        division d1 = new division();
        System.out.println("Enter Your Name:");
        Scanner scn = new Scanner(System.in);
        String a = scn.next();
        System.out.println("Good Morning!"+a);
        System.out.println();
        System.out.println("Please choose option from below");
        System.out.println();
        System.out.println("1.Addition 2.Subtraction 3.Multiplication 4.Division");
        int option = scn.nextInt();
        while (i!=0)
        {
        if (option==1)
        {
            a1.add();
        }
        else if (option == 2)
        {
            s1.sub();
        }
        else if (option == 3)
        {
            m1.mul();
        }
        else if (option == 4)
        {
            d1.div();
        }
        else
        {
            System.out.println("Please enter valid number");
        }
        }
        System.out.println("Do you wish to continue");
        int b = scn.nextInt();
        if (b==0)
        {
            System.out.println("Thanks for using the calculator Program"+a);
            System.out.println("Have a great day!");
        }
    }


}

最佳答案

当您实现一个接口(interface)时,您需要在实现类中实现该接口(interface)的所有方法。

在您的示例中,您应该实现 add()sub()mul()div() 在任何实现接口(interface) calci

的类中

关于Java抛出错误 "<Class Name> is not abstract and does not override abstract method in the <Interface>",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25718142/

相关文章:

java - 从 java 类调用 doGet Servlet 方法

java - 使用 Spring Boot 测试 OneToMany 与 Postman 的关系时出错

java - 如何使用dojo查找操作类是否返回错误或成功?

java - 从 JSP 页面中的 servlet 调用方法,使用该 JSP 页面中的参数的方法

java - 在 Spring 中创建 URL 的最佳方法

java - 扫描仪列出错误

java - Ant - 如何排除 Java 测试文件?

java - 是什么让最新版本的 JVM 更快?

java - 在类的一个实例上找不到公共(public)符号变量 (Java)

java - 插入包含日期的查询格式