Sorry guys,
but i am asking to my self why we have this "public Cat( ) { }" empty?
Function works also without that.
Someone could explain me the reason?
<3
Why we have public Cat() {} empty?
Under discussion
Comments (3)
- Popular
- New
- Old
You must be signed in to leave a comment
Hoang Khai
5 July 2019, 15:24
that is the constructor. If you declare variables in the constructor, all instances which are cat1 and cat2 will have the same value. I think so:))
0
Han
24 June 2019, 20:25
It is not a function nor a method.
notice that there is no return type so this is a constructor.
When you provide no constructor for your class, java will create a default constructor. (https://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.8.9)
So if you don't create this constructor actually java will insert this:
my guess is that the creators of this task don't want that behaviour somehow :) 0
alezalez
23 June 2019, 16:12
In this case method "Cat() " does nothing. And, it also works - to do nothing :) What number this task?
0