two constructor creating problem
public class abcd {
String name;
int salary;
int enom;
abcd(String name)
{
this.name=name;
}
abcd(int salary)
{
this.salary=salary;
}
abcd(int enom)
{
}
the error is that
"duplicate methods";
and it is only for the latter two... it does not give for about two.... plzzz help
Re: two constructor creating problem
When having multiple constructors the compiler can only tell the difference by the parameters, since both constructors use only a single int the compiler cannot tell the difference and throws an error.
Re: two constructor creating problem
It is the job of a constructor to make sure all of the instance fields are properly initialised. So, consider having a single constructor that is passed all of the values.
Re: two constructor creating problem
Quote:
Originally Posted by
Bandicoot802
When having multiple constructors the compiler can only tell the difference by the parameters, since both constructors use only a single int the compiler cannot tell the difference and throws an error.
thanks