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

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

試圖學(xué)習(xí)課程陷入了死胡同

試圖學(xué)習(xí)課程陷入了死胡同

C#
qq_遁去的一_1 2023-08-20 15:46:18
我的秋季學(xué)期將包括使用 c#,所以我正在努力爭(zhēng)取盡可能的優(yōu)勢(shì)。我想做的第一件事是了解抽象類,但我在使我的代碼工作時(shí)遇到困難。它是一個(gè)“item”類,有 3 個(gè) .cs 文件,包括主項(xiàng)目類。這是抽象類。using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApp6{    abstract public class item    {        public abstract string prodName { set; }        public abstract int amount();    }}這是子類。using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApp6{    public class ProteinPowder : item // Says it doesn't implement anything.    {        private string name;        private int itemAmount;        public proPowder(string name, int amount) // Is this correct?        {            this.name = name;            this.itemAmount = amount;        }        public string Name { set => name = value; }        public int Amount { set => itemAmount = value; }    }}主項(xiàng)目目前是空的。我認(rèn)為可以通過(guò)正確實(shí)施 ProteinPowder 來(lái)解決這些問(wèn)題,但我無(wú)法讓它發(fā)揮作用。有人可以指出我做錯(cuò)了什么嗎?** 編輯 ***這看起來(lái)更好嗎?using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApp6{    public class ProteinPowder : item    {        private string name;        private int itemAmount;        public ProteinPowder(string name, int amount)        {            this.name = name;            this.itemAmount = amount;        }        public int Amount { set => itemAmount = value; }        public override string prodName { set => throw new NotImplementedException(); }        public override int amount()        {            throw new NotImplementedException();        }    }}
查看完整描述

1 回答

?
寶慕林4294392

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

簡(jiǎn)而言之,抽象類是說(shuō)“任何實(shí)現(xiàn)我的東西都必須為我擁有的所有抽象屬性/方法提供實(shí)現(xiàn)”。


就您而言,item有 2 個(gè)抽象項(xiàng)目。prodName和amount。


這意味著在你的ProteinPowder課堂上,你需要實(shí)現(xiàn)這些,例如


public override string prodName { set => /*do something specific for ProteinPowder*/}


public override int amount()

{

    // do something specific for ProteinPowder

}

你提出的第二件事public proPowder(string name, int amount) // Is this correct?,答案是否定的。


由于缺少返回類型,我假設(shè)這應(yīng)該是構(gòu)造函數(shù)。構(gòu)造函數(shù)必須與類的名稱匹配,因此應(yīng)為


public ProteinPowder(string name, int amount)


查看完整回答
反對(duì) 回復(fù) 2023-08-20
  • 1 回答
  • 0 關(guān)注
  • 137 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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