Z wniosków które wyciągnąłem z poprzednich zadań :
public Kot() { licznikKotow++;} to jest konstruktor domyślny
public Kot( int licznikKotow ) { this.licznikKotow = licznikKotow++;} a to jest normalny konstruktor
Czym one się różnią ?
Różnice między konstruktorem domyślnym a normalnym
Dyskutowane
Komentarze (1)
- Popularne
- Najnowsze
- Najstarsze
Musisz się zalogować, aby dodać komentarz
Guadalupe Gagnon
25 maja 2022, 21:01
In the English version the task specifically says that we should use the constructor:
To increase the count variable.
If that is true for the polish version as well then using the:
constructor would be incorrect and fail the task
P.S.
A default constructor is used when no other constructor is specified. It behave the same as a constructor with no arguments and no code, but if ANY constructor is there then it is not the default constructor:
This code below uses the default constructor because no constructor is specified:
While the code below, while being functionally the same, has a constructor so no default constructor will be used:
0