javasirc: you changed the return type and left of the return (this);, it needs to return itself since the next SetN("...") is called on the value returned by the previous SetN("...")
I would advise you to use properties instead though like Telastyn suggested.
C# function overloading question
Another option is to rather than do this:
...you could do this:
You still need to write multiple constructors, but they get easier and easier to write. [smile]
class Demo { int a, b, c; public Demo(int a, int b, int c) { this.a = a; this.b = b; this.c = c; } public Demo(int a, int b) { this.a = a; this.b = b; this.c = 3; } public Demo(int a) { this.a = a; this.b = 2; this.c = 3; } public Demo() { this.a = 1; this.b = 2; this.c = 3; }}
...you could do this:
class Demo { int a, b, c; public Demo(int a, int b, int c) { this.a = a; this.b = b; this.c = c; } public Demo(int a, int b) : this(a, b, 3) { } public Demo(int a) : this(a, 2) { } public Demo() : this(1) { }}
You still need to write multiple constructors, but they get easier and easier to write. [smile]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement