第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

為什么子類(lèi)方法打印 null ?我究竟做錯(cuò)了什么?

為什么子類(lèi)方法打印 null ?我究竟做錯(cuò)了什么?

一只甜甜圈 2023-09-27 16:55:57
為什么我的代碼將 null 作為輸出值而不是傳遞的參數(shù)?家長(zhǎng)班級(jí):class Language{  protected String name;  protected int numSpeakers;  protected String regionsSpoken;  protected String wordOrder;    public Language(String getName, int getNumSpeakers, String getRegionsSpoken, String getWordOrder){    this.name = getName;    this.numSpeakers = getNumSpeakers;    this.regionsSpoken = getRegionsSpoken;    this.wordOrder = getWordOrder;  }    public void getInfo(){    System.out.println(name+ " is spoken by "+numSpeakers+"  people mainly in "+regionsSpoken);    System.out.println("The language follows the word order: "+wordOrder);  }    public static void main(String[] args){    Mayan mayanLanguage = new Mayan("Ki'che'",30000);    mayanLanguage.getInfo();  }}兒童班:class Mayan extends Language {  protected String name;  protected int numSpeakers;    Mayan(String languageName,int speakers ){    super(languageName,speakers,"Central America","verb-object-subject");  }    @Override  public void getInfo() {    System.out.println(name+" is spoken by "+numSpeakers+" people mainly in Central America.");    System.out.println("The language follows the word order: verb-object-subject");    System.out.println("Fun fact: "+name+" is an ergative language.");  }}我查看了代碼并嘗試通過(guò)更改來(lái)解決它,但似乎沒(méi)有任何效果,我陷入了代碼中沒(méi)有看到的錯(cuò)誤是什么。預(yù)期是:Ki'che' 有 2330000 人使用,主要分布在中美洲。該語(yǔ)言遵循詞序:動(dòng)詞-賓語(yǔ)-主語(yǔ) 有趣的事實(shí):Ki'che' 是一種作格語(yǔ)言。實(shí)際是:null 主要在中美洲有 0 人使用。該語(yǔ)言遵循詞序:動(dòng)詞-賓語(yǔ)-主語(yǔ) 有趣的事實(shí):null 是一種作格語(yǔ)言。
查看完整描述

1 回答

?
搖曳的薔薇

TA貢獻(xiàn)1793條經(jīng)驗(yàn) 獲得超6個(gè)贊

在Mayan你有領(lǐng)域


protected String name;

protected int numSpeakers;

刪除這些將解決您的問(wèn)題。發(fā)生此問(wèn)題的原因是因?yàn)楫?dāng)您定義上面的兩行時(shí),您隱藏了這兩個(gè)字段,Language并且您必須從Languagelike super.name、super.numSpeakers等訪(fǎng)問(wèn)這些字段...


您可能正在追求類(lèi)似以下的內(nèi)容。


public class Mayan extends Language {

    private static final String REGION = "Central America";

    private static final String WORD_ORDER = "verb-object-subject";


    public Mayan(String languageName, int speakers) {

        super(languageName, speakers, REGION, WORD_ORDER);

    }


    @Override

    public void getInfo() {

        super.getInfo();

        System.out.println("Fun fact: " + name + " is an ergative language.");

    }

}

正如加文指出的,訪(fǎng)問(wèn)修飾符可以受到限制。如果您在程序的單個(gè)包中工作,您最終可能會(huì)得到類(lèi)似的結(jié)果


Language.java


class Language {

    String name;

    private int numSpeakers;

    private String regionsSpoken;

    private String wordOrder;


    Language(String getName, int getNumSpeakers, String getRegionsSpoken, String getWordOrder) {

        this.name = getName;

        this.numSpeakers = getNumSpeakers;

        this.regionsSpoken = getRegionsSpoken;

        this.wordOrder = getWordOrder;

    }


    void getInfo() {

        System.out.println(name + " is spoken by " + numSpeakers + "  people mainly in " + regionsSpoken);

        System.out.println("The language follows the word order: " + wordOrder);

    }


    public static void main(String[] args) {

        Mayan mayanLanguage = new Mayan("Ki'che'",30000);

        mayanLanguage.getInfo();

    }

}

Mayan.java


class Mayan extends Language {

    private static final String REGION = "Central America";

    private static final String WORD_ORDER = "verb-object-subject";


    Mayan(String languageName, int speakers) {

        super(languageName, speakers, REGION, WORD_ORDER);

    }


    @Override

    void getInfo() {

        super.getInfo();

        System.out.println("Fun fact: " + name + " is an ergative language.");

    }

}


查看完整回答
反對(duì) 回復(fù) 2023-09-27
  • 1 回答
  • 0 關(guān)注
  • 119 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)