+ 2
Confusion in creating java objects.
sometimes we code for creating object of class like Car objCar = new Car (): but sometimes we have to put zero on braces like Car objCar = new Car (0): please explain the difference
3 odpowiedzi
+ 6
the first one is using a no argument constructor and the second one is using a constructor with an argument.
it's just like passing an argument to a method. when the object is being created, the object will use the input you gave it (0 in your case) in some way to initialise the state of the object.
+ 2
It depends from the constructor:
public Car()
{ }
or
public Car(int i)
{ }
+ 1
🤔