Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Chained Account Constructors | Constructors and Overloading
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
C# OOP Class Construction Drills

bookChallenge: Chained Account Constructors

Oppgave

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.

Løsning

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 1. Kapittel 6
single

single

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

close

bookChallenge: Chained Account Constructors

Sveip for å vise menyen

Oppgave

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.

Løsning

Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 1. Kapittel 6
single

single

some-alt