calculator.java

来自「介绍了java的一些应用」· Java 代码 · 共 60 行

JAVA
60
字号
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package Calculator;/** * * @author liuwei */class fathercalcul{    double a,b,c; /*   fathercalcul(double a1,double b1){        a=a1;b=b1;    }*/    void setnum(double a1,double b1)   {        a=a1;b=b1;    }    void add(){        System.out.println("call father class's add function");       c=a+b;    }    void minus(){        c=a-b;    }    void multiply(){        c=a*b;    }    void divide(){        if(b!=0)c=a/b;        else             System.out.println("error");    }    void showanswer(){        System.out.println("call father class's function,the answer is"+c);    }}class soncalcul extends fathercalcul{    //soncalcul(){}    void add(){         System.out.println("call son class's add function");        c=a+b;    }     void showanswer(){         super.showanswer();        System.out.println("call son class's function,the answer is"+c);    }    public static void main(String[] args){        fathercalcul fc=new fathercalcul();        soncalcul sc=new soncalcul();        fc.setnum(5.2,6.3);        sc.setnum(5.0,7.2);        fc.add();        fc.showanswer();        sc.add();        sc.showanswer();    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?