public void Circle(){
.......
}
public Circle(){
.......
}
what effects when we used void .
i know void means null.
can any one please clarify about how this is different
Resolved
Comments (5)
- Popular
- New
- Old
You must be signed in to leave a comment
Daniel
15 May 2020, 19:17
Constructors don't have a return type.
0
Mike Taylor
20 February 2020, 03:08
This first one defines a method - "()" no parameters being passed into method, "void" not returning any value.
The second one is only used by program if creating a Circle object, that form is specifically a constructor.
0
Ashish RajAnand
20 February 2020, 04:01
thanks a lot ,I know that bro .
if we create object of circle then
is there any error ?
0
Mike Taylor
20 February 2020, 04:33
Definitely ran this myself to be sure, and found it functioned not as desired.
When line 12 runs it looks for constructor "public Car()" but can't find it, so the info "BMW" and "1000" are not assigned to it. So if we call bugatti.model or bugatti.maxSpeed, they are both null;
If you add a line (say line 13) "bugatti.Car(), that is call the method, then your values will get assigned and can now be referenced.
So your code above compiles but won't work as effectively as it should.
0
Ashish RajAnand
20 February 2020, 07:02
thanks bro
0