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

bookChallenge: Chained Account Constructors

Taak

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.

Oplossing

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 6
single

single

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

Suggested prompts:

Can you explain this in simpler terms?

What are the main points I should remember?

Can you give me an example?

close

bookChallenge: Chained Account Constructors

Veeg om het menu te tonen

Taak

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.

Oplossing

Switch to desktopSchakel over naar desktop voor praktijkervaringGa verder vanaf waar je bent met een van de onderstaande opties
Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 6
single

single

some-alt