Click here to Skip to main content
16,017,857 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
why java does not support default argument constructors as in c++?
Posted
Comments
Nish Nishant 25-Oct-10 20:30pm    
Do you mean constructors with default arguments?

So that you can have a reason to use C++?
 
Share this answer
 
Comments
Nish Nishant 25-Oct-10 20:30pm    
Unlikely to be so.
It's a bit more long-winded, but you can achieve the same effect with multiple constructors:

C++
thing(int required, int optional = 3) {
  field1 = required;
  field2 = optional;
}

Java
thing(int required, int optional) {
  field1 = required;
  field2 = optional;
}
thing(int required) {
  this(required, 3);
}

[This second form works in C++ too!]

Peter
Vote for answers, and mark them accepted if you like them.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900