promotion image of download ymail app
Promoted

想知道JAVA這幾行程式碼片段的意思到底是甚麼???求解

abstract class work{

String wno;

work(String s)

{wno=s;}

//建立一個每月收入抽象的方法

abstract double monthPay();

}

//建立一個SalaryWorker類別,繼承work,在此方法中有寫入紅利變數,但設定成0

class SalaryWorker extends work{

int mp;//年薪

int redp=0;//紅利

//建構子初始化員工編號、年薪

SalaryWorker(String s ,int i)

{super(s);mp=i;}

double monthPay(){return (mp/12.0+redp);}

}

這是一個"員工薪資制度"的程式碼片段,想請問一下work(String s)、{wno=s;}、{super(s);mp=i;}這三行ㄉ意思和關聯到底是甚麼~求解????

1 個解答

評分
  • John
    Lv 7
    5 年前
    最佳解答

    如果咁樣寫可能易明點。

    abstract class Work {

    String workerNumber;

    public Work(String workerNumber) {

    this.workerNumber = workerNumber;

    }

    }

    class SalaryWorker extends Work {

    private int annualSalary;

    public SalaryWorker(String workerNumber, int annualSalary) {

    super(workerNumber);

    this.annualSalary = annualSalary;

    }

    }

    這樣就可以用

    Work john = new SalaryWorker("John", 1200);

    System.out.printf("Month pay: $%,.2f%n", john.monthPay());

    • Commenter avatar登入以對解答發表意見
還有問題?馬上發問,尋求解答。