I am new to Java and I understand constructors(I guess), but why does my code does not work until I construct an empty constructor? When I already have a constructor with parameters etc of that class.
Asked
Active
Viewed 206 times
1
Md Golam Rahman Tushar
- 1,847
- 1
- 9
- 25
mrAKU
- 11
- 1
-
1Does this answer your question? [Java default constructor](https://stackoverflow.com/questions/4488716/java-default-constructor) – Šimon Kocúrek Mar 25 '20 at 20:02
-
it seems that you declared a constructor taking a number of arguments. so the no-arguments constructor is no longer available. You need to either declare a no-arg constructor, or to pass in the required arguments – Daniele Mar 25 '20 at 20:07
1 Answers
1
Because you don't have a constructor with no argument at your class. That's why when you are trying to create an instance using the no argument constructor it showing you the error.
Note that, If you don't define any constructor then the class have a default constructor with no parameter. But if you do declare a constructor then there is no default constructor, only the ones you define.
Hope this will clear your confusion.
Mark Rotteveel
- 90,369
- 161
- 124
- 175
Md Golam Rahman Tushar
- 1,847
- 1
- 9
- 25