This class has not constructor.
Default constructor. If you don't define a constructor for a class, a default parameterless constructor is automatically created by the compiler. The default constructor calls the default parent constructor (super()) and initializes all instance variables to default value (zero for numeric types, null for object references, and false for booleans).
What does default constructor here? String=null or String=blue?
If String=Blue,it does by default constructor?
Not quite. The default constructor does nothing with any of the fields; they are filled with default values, which in the case of a reference type is null, at the place of declaration.
Abimaran Kugathasan wrote:. . . the variable "name" is initialized to null. It's done by the default constructor.
It is bad practice to have a class with fields and not set them up in the constructor; it allows your object to be in an inconsistent state.When you first buy a car, it is travelling at a speed of 0. It is best to initialise all fields, even to 0 which is the same as the default value.
No. Your declaration does that. Look:
abalfazl hossein wrote: . . . Does default constructor initialize colour to "blue"?
. . . and as I said
you earlier wrote:
The following was inaccurate and misleading:
The default constructor does nothing with any of the fields . . .
* * * * *
Abimaran Kugathasan wrote: . . . the variable "name" is initialized to null. It's done by the default constructor.
Why don't you add a print statement and print out the colour and you will see whether it comes out as blue or null.