Reputation: 2467
I know you can have multiple constructors, for example:
public Game (int num, boolean truth) {
}
public Game (int num) {
this(num, false);
}
Can the same be done for getter methods? So I can have two parameters, but if the user only wants to use one, the other will automatically be filled in. Such as
public int wins (int num, boolean truth) {
return num*2;
}
public int wins (int num) {
this(num, false);
}
Upvotes: 0
Views: 121
Reputation: 6276
Yes you can do this, this is called overloading:
public class DataArtist { ... public void draw(String s) { ... } public void draw(int i) { ... } public void draw(double f) { ... } public void draw(int i, double f) { ... } }
Upvotes: 1
Reputation: 8657
You can declare a delegate methods like:
public int wins (int num, boolean truth) {
return num * 2;
}
public int wins (int num) {
return wins(num, false);
}
In this case this
keyword is use only to call constructors.
Upvotes: 1