定义一个接口IPerson,封装一个方法:
void print()//输出人员有关信息利用IPerson接口规范,定义一个类Teacher,表示某学校教师的最基本信息。
4个成员变量:工号num,
姓名name, 
工龄workAge,
职务job;
3个成员方法:
Teacher ( String num,
String name,
int workAge,
String job);
Teacher( String num,
double workAge);
输出教师的工号和工龄:print();請問這要怎麽回答...如果解决了...我下麵就知道怎麽做了...

解决方案 »

  1.   


    public interface IPerson {
    void print();}class Teacher implements IPerson{
    String name;
    double workAge;
    String job;
    String num;
    Teacher(String name,double workAge,String job,String num){
    this.name = name;
    this.job = job;
    this.num = num;
    this.workAge = workAge;

    }
    public void print(){
    System.out.println("教师的工号和工龄分别是: " + num + ", " + workAge);
    }
    }
      

  2.   

    [Quote=引用 4 楼 ouran1987 的回复:]
    引用 1 楼 coldanimal 的回复:
    Java code
    public interface IPerson {
    void print();}class Teacher implements IPerson{
    String name;
    double workAge;
    String job;
    String num;
    Teacher(String name,double workAge,String job,String num){
    this.name = name;
    this.job = job;
    this.num = num;
    this.workAge = workAge;}
    public void print(){
    …完美了
      

  3.   

    請問this 在這裏麵有什麽用??可以不用嗎???
      

  4.   

    this指对象本身,
    可以不用,只要构造函数的参数名,与对象的属性变量名称定义不一样就可以
      

  5.   

    实际中,一般是相同的,为了更好的理解。所以最好还是掌握this的使用。
      

  6.   

    public interface IPerson {
        void print();}class Teacher implements IPerson{
        String name;
        double workAge;
        String job;
        String num;
       Teacher ( String num, String name, double workAge, String job){ 
           this(num,workAge);
           this.name = name;
           this.job = job;      
         }
       Teacher(String num,double workAge){
            this.num = num;
            this.workAge = workAge;
         }

        public void print(){
            System.out.println("教师的工号和工龄分别是: " + num + ", " + workAge);
        }
    }