解决方案 »

  1.   

    忘记了贴 Info类的定义、public class Info {
    String title = "non-init";
    String author = "non-init";
    String wordsCount = "non-init";

    public String getTitle() {
    return title;
    }
    public void setTitle(String title) {
    this.title = title;
    }
    public String getAuthor() {
    return author;
    }
    public void setAuthor(String author) {
    this.author = author;
    }
    public String getWordsCount() {
    return wordsCount;
    }
    public void setWordsCount(String wordsCount) {
    this.wordsCount = wordsCount;
    }
    }
      

  2.   

    package test7;public class MianXiangJieKou
    {
    public static void main(String[] args)
    {
    Book b1 = new Novel();
    Book b2 = new Magazine();
    Mather mather = new Mather();

    mather.read(b1);
    mather.read(b2);
      }
    }interface Book
    {
    public void read();
    }
    class Novel implements Book
    {
    @Override
    public void read()
    {
    System.out.println("读小说内容");
    }
    }
    class Magazine implements Book
    {
    @Override
    public void read()
    {
    System.out.println("读杂志内容");
    }
    }
    class Mather
    {
    //mather能读书,不论是小说或者杂志。只要这本读物实现了Book都能被mather读。
    //这就是面向接口的好处。
    public void read(Book b)
    {
    b.read();
    }
    }
    接口, 你可以看做是电脑的USB接口。定义了某个功能的名字, 然后具体的那个插件,只要插上去就可以实现相应的功能。