日期:2014-05-20  浏览次数:20705 次

帮我看下这个代码 编译提示需要'{' 本人菜鸟 望高手解答
public abstract class Student {
  private String name;
  private String no;
  public abstract void printlnfo() {
  
  }
  public Student() {
  no="20100701020xx";
  name="lx";
  }
  public static void print() {
  System.out.println("name:" +name);
  System.out.println("no:" +no);
  }
}

public class MaleStudent extents Student {
  private String gender;
  public MaleStudent(String gender) {
  this.gender=gender;
  }
  public static void printlnfo() {
  System.out.println("name:"+name);
  System.out.println("no:+no");
  System.out.println("gender:+gender");
  }
  public static void main(String[] args) {
  MaleStudent m=new MaleStudent();
  printlnfo();  
  }
}

------解决方案--------------------
有很多地方需要改动,代码贴到下面你自己找一下问题吧,看你语法还是很生疏,找本教材学习下
Java code


abstract class Student {
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getNo() {
        return no;
    }

    public void setNo(String no) {
        this.no = no;
    }

    private String no;
    public abstract void printlnfo();

    public Student() {
        no="20100701020xx";
        name="lx";
    }
    public void print() {
        System.out.println("name:" +this.getName());
        System.out.println("no:" +no);
    }
}

public class MaleStudent extends Student {
    private String gender;

    public MaleStudent(String gender) {
        super();
        this.gender=gender;
    }
    @Override
    public void printlnfo() {
        System.out.println("name:"+this.getName());
        System.out.println("no:+no");
        System.out.println("gender:+gender");
    }
    public static void main(String[] args) {
        MaleStudent m=new MaleStudent("man");
        m.printlnfo();
    }
}