I just started learning Java and I have a problem regarding method-overloading.
I want to know if I can call a variation of an overloaded method inside the scope of another variation of the overloaded method in question.
My main question is: What problems could possibly arise from doing that?
For example:
public class RoomClass {
int roomNo = 1;
String roomType = "Lecture Hall";
String roomArea = "First Floor";
boolean ACMachine = true;
protected void setData(int roomNo, String roomType, String roomArea, boolean ACMachine) {
setData(roomNo);
setData(roomType, roomArea);
setData(ACMachine);
}
protected void setData(int roomNo) {
this.roomNo = roomNo;
}
protected void setData(String roomType, String roomArea) {
this.roomType = roomType;
this.roomArea = roomArea;
}
protected void setData(boolean ACMachine) {
this.ACMachine = ACMachine;
}
}
The code above is about an exercise. I couldn't find an answer to my question online or in a book. What I am trying to do is to avoid repeating code, so I figured "why not call on the other methods, since they are doing exactly what I need?". So I just aggregated all the other methods into the first one.