Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Challenge: Encapsulated Product Class | Class Design and Encapsulation
C# OOP Class Construction Drills

bookChallenge: Encapsulated Product Class

Tarea

Swipe to start coding

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 Product inside the ConsoleApp namespace.
  • Add two private fields: name (of type string) and price (of type decimal).
  • Implement a public method GetName() that returns the value of name.
  • Implement a public method SetName(string value) that sets the value of name.
  • Implement a public method GetPrice() that returns the value of price.
  • Implement a public method SetPrice(decimal value) that sets the value of price only if the value is not negative.
  • Do not add any code outside the Product class; do not change a Main method or any additional classes.

Solución

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 4
single

single

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

close

bookChallenge: Encapsulated Product Class

Desliza para mostrar el menú

Tarea

Swipe to start coding

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 Product inside the ConsoleApp namespace.
  • Add two private fields: name (of type string) and price (of type decimal).
  • Implement a public method GetName() that returns the value of name.
  • Implement a public method SetName(string value) that sets the value of name.
  • Implement a public method GetPrice() that returns the value of price.
  • Implement a public method SetPrice(decimal value) that sets the value of price only if the value is not negative.
  • Do not add any code outside the Product class; do not change a Main method or any additional classes.

Solución

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 4
single

single

some-alt