0
What if I use void in constructor? (Java)
Eg: class a { public void a{ } }
2 RĂ©ponses
+ 2
If you make a "constructor" giving it a return type (in this case void) it will stop to be a constructor and will be a simple function, so when you create an object the code inside that "void constructor" isn't going to run BUT you can call it like a normal function using:
Object.ObjectClass();
Have a nice day đ§đŒââïžđ§đŒââïžđ§đŒââïž
+ 4
Then it will no longer be a constructor!
Though your code will not show any error but that will turn into a method from a constructor đŠ
You can make your constructor even after making this function!
class A {
public void A(){}
public A(){}
}
This code will not show any error!
And these will work perfectly!