Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Challenge: Chained Account Constructors | Constructors and Overloading
C# OOP Class Construction Drills

bookChallenge: Chained Account Constructors

Tarea

Swipe to start coding

Practice constructor chaining by building an Account class that offers flexibility in how accounts are created. Use overloaded constructors to allow for different initialization scenarios, and ensure all constructors ultimately delegate initialization to a single constructor to avoid code duplication.

  • The Account class must have three constructors: a default constructor, a constructor that takes an accountNumber, and a constructor that takes both an accountNumber and a balance.
  • The default constructor must set both AccountNumber and Balance to zero.
  • The constructor with one parameter must set AccountNumber to the provided value and Balance to zero.
  • The constructor with two parameters must set AccountNumber and Balance to the provided values.
  • All constructors must use constructor chaining so that only one constructor contains the actual assignment logic.
  • Do not duplicate assignment code across constructors.

Solución

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 6
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: Chained Account Constructors

Desliza para mostrar el menú

Tarea

Swipe to start coding

Practice constructor chaining by building an Account class that offers flexibility in how accounts are created. Use overloaded constructors to allow for different initialization scenarios, and ensure all constructors ultimately delegate initialization to a single constructor to avoid code duplication.

  • The Account class must have three constructors: a default constructor, a constructor that takes an accountNumber, and a constructor that takes both an accountNumber and a balance.
  • The default constructor must set both AccountNumber and Balance to zero.
  • The constructor with one parameter must set AccountNumber to the provided value and Balance to zero.
  • The constructor with two parameters must set AccountNumber and Balance to the provided values.
  • All constructors must use constructor chaining so that only one constructor contains the actual assignment logic.
  • Do not duplicate assignment code across constructors.

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 1. Capítulo 6
single

single

some-alt