📄 calculator.java
字号:
/* * 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -