多谢拉  我想写一个自己家族的程序 想都用到继承,多态,接口,抽象,等

解决方案 »

  1.   

    什么叫“自己家族的程序”
    ===========
    应该就是
    class people {}class grandFather extends people{}class father extends grandFather implement grandMother {}
    implement 用的不是很恰当,呵呵
      

  2.   

    错啦~~~~ 楼主如果让你去继承你的父亲,而你的父亲去继承你的爷爷,那你就错了。
    现实生活中的家族关系根本不符合OO的继承关系。OO中的超类相比派生类而言总是具有更多的抽象性或不完整性,所以才需要派生类去extend,即扩展。而你的爷爷,你的父亲和你,三者在抽象级别和完整性上是一样的,三者都是完整的人,都是具像的。所以,这种关系不能用继承来实现。如果要用继承的话,你可以把你的家族成员抽象为人类,再分别派生出男人、女人,可以把夫妻,父母,兄弟姐妹这些关系分别定义为接口。比如,一个男人可实现丈夫、父亲、哥哥、弟弟等这些接口,而一个女人可以实现妻子、母亲、姐姐、妹妹接口等等。更多的关系可以依此类推。
      

  3.   

    继承英文:inheritance解释:Inheritance is an integral part of Java (and all OOP languages). It turns out that you’re always doing inheritance when you create a class, because unless you explicitly inherit from some other class, you implicitly inherit from Java’s standard root class Object. The syntax for composition is obvious, but to perform inheritance there’s a distinctly different form. When you inherit, you say “This new class is like that old class.” You state this in code by giving the name of the class as usual, but before the opening brace of the class body, put the keyword extends followed by the name of the base class. When you do this, you automatically get all the fields and methods in the base class.中文:继承是所有 OOP 语言和 Java  语言的组成部分。当你在创建一个类时,你总是在继承,因此,除非你已明确指出要从其他类中继承,否则你就是在隐式地从Java 的标准根源类object 
    进行继承。
    组合的语法比较平实,但要执行继承,其语法却要采用截然不同的形式。在继承过程中,你 
    需要先声明:“新类与旧类相似。”通常,你首先给类确定一个名称,但在书写类主体的左边 
    花括号之前,应先写下关键字 extends,并在其后写下基类的名称。当你这么做时,会自动 
    得到基类中所有的数据成员和成员方法。出自think in java3th实例么:"学生",可以被"大学生"和"中学生"继承。