public class Module
{
// required instance variables
private String codeModule, titleModule;
private int pointsModule;
//three-argument constructor receiving a code, a title string, and a
//number of points,
//which sets the code, title and points data of the created object to
//the received values.
public Module(String aCode, String aTitle, int aPoints)
{
codeModule = aCode;
titleModule = aTitle;
pointsModule = aPoints;
}
//set the instance data value codeModule to received argument newCode.
public void setaCode(String newCode)
{
codeModule = newCode;
}
//set the instance data value titleModule to received argument
//newTitle.
public void setaTitle(String newTitle)
{
titleModule = newTitle;
}
//set the instance data value pointsModule to received argument
//newPoints.
public void setaPoints(int newPoints)
{
pointsModule = newPoints;
}
//return the instance data values of codeModule.
public String getaCode()
{
return codeModule;
}
//return the instance data values of titleModule.
public String getaTitle()
{
return titleModule;
}
//return the instance data values of pointsModule.
public int getaPoints()
{
return pointsModule;
}
//returns a string containing the full details of the module,
//giving the module code, title and number of points in parentheses
public String toString()
{
return "Module code " + codeModule + ", Module Title " + titleModule + ", Module
Points (" + pointsModule + ")";
}
//returns true if the module referenced by o has the same instance
//variable values
//as the object on which this method is invoked; otherwise the method
public boolean equals(Object o)
{
Module m = (Module)o;
return codeModule.equals(m.codeModule) && titleModule.equals(m.titleModule) &&
pointsModule == m.pointsModule;
}
//returns true if the code string begins with a capital letter and has
//four characters;
//otherwise the method returns false.
public Boolean isCode()
{
if (codeModule.length()== 4 && (codeModule.charAt(0) >= 'A'
&&(codeModule.charAt(2) <= 'Z')))
{
return true;
}
else
{
return false;
}
}
}
Меня попросили идентифицировать любые методы, которые перегружают или переопределяют любые другие методы, насколько я понимаю, перегрузка происходит, когда у класса более одного метода с одинаковым именем, но с разными сигнатурами (т.е. типчисло или порядок их формальных аргументов должен отличаться), а определение метода в подклассе переопределяет унаследованный метод из суперкласса или одного из его наследственных классов, если сигнатура метода в подклассе точно совпадает с сигнатурой унаследованного метода иони имеют одинаковый тип возврата.Закрытые методы в суперклассе не переопределяются в подклассе, так как они не наследуются.
Насколько я понимаю, у меня нет методов с одинаковыми именами, которые нельзя перегрузить, и я не расширил другойкласс, поэтому я не могу переопределить!Будет ли это правильно, или я что-то пропустил.
Спасибо, bb
(меня также попросили отформатировать правильно из предыдущих вопросов, я надеюсь, что это правильно)