2010-12-29 2 views
0
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는

+1

의 방법은 toString() 우선인가? – sblundy

답변

1

당신은 당신의 정의를 맞아하지만 Object

+0

이 답변은 정확하지만 완전하지는 않습니다;) –

6

이해가 정확하지만 모든 개체를 암시하므로, java.lang.Object을 확장 기억 (나는 또한 이전 질문에서 올바른 포맷하라는 메시지가있다, 난이 올바른 바랍니다) 해당 클래스의 메서드를 재정의하는지 여부를 확인해야합니다. 이 숙제 질문

+0

카메론 감사합니다. 그렇습니다. 그렇지만 저는 단지 제 이해를 확인하고 있습니다. – user445714

관련 문제