セクション 2. 章 4
single
Challenge: Encapsulated Product Class
メニューを表示するにはスワイプしてください
タスク
スワイプしてコーディングを開始
Write the complete Product class starting from the class declaration inside the ConsoleApp namespace. Your class must demonstrate encapsulation by controlling access to its internal data.
- Define
public class Productinside theConsoleAppnamespace. - Add two private fields:
name(of typestring) andprice(of typedecimal). - Implement a public method
GetName()that returns the value ofname. - Implement a public method
SetName(string value)that sets the value ofname. - Implement a public method
GetPrice()that returns the value ofprice. - Implement a public method
SetPrice(decimal value)that sets the value ofpriceonly if the value is not negative. - Do not add any code outside the
Productclass; do not change aMainmethod or any additional classes.
解答
すべて明確でしたか?
フィードバックありがとうございます!
セクション 2. 章 4
single
AIに質問する
AIに質問する
何でも質問するか、提案された質問の1つを試してチャットを始めてください