Challenge: Chained Account Constructors
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
Accountclass must have three constructors: a default constructor, a constructor that takes anaccountNumber, and a constructor that takes both anaccountNumberand abalance. - The default constructor must set both
AccountNumberandBalanceto zero. - The constructor with one parameter must set
AccountNumberto the provided value andBalanceto zero. - The constructor with two parameters must set
AccountNumberandBalanceto 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
Takk for tilbakemeldingene dine!
single
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår
Fantastisk!
Completion rate forbedret til 4.17
Challenge: Chained Account Constructors
Sveip for å vise menyen
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
Accountclass must have three constructors: a default constructor, a constructor that takes anaccountNumber, and a constructor that takes both anaccountNumberand abalance. - The default constructor must set both
AccountNumberandBalanceto zero. - The constructor with one parameter must set
AccountNumberto the provided value andBalanceto zero. - The constructor with two parameters must set
AccountNumberandBalanceto 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
Takk for tilbakemeldingene dine!
single