比如父类superclass中有一个方法,supermethod(){System.out.print("生物"); }; 那么在子类中就可以调用这个方法,只有一个语句是不可以的。 thinking in java, 特别好的一本书,如果你要英文的话,网上哪里都有,如果中文,只有第一版,翻译得很烂,建议你看英文。
初学者看Thinking in java似乎不大恰当 他似乎连面向对象都不清楚 看JAVA思想难度高了点 看看《Java 核心技术》第一卷:基础知识吧 很简单很详细的说
呵呵。 也是。那先看《Java语言和面向对象程序设计》 王克宏编写的好像。
java中可以说只有类,对象,可以继承类,类中只有属性和方法..不是一条语句..
The members of a class type are all of the following:Members inherited from its direct superclass (§8.1.3), except in class Object, which has no direct superclass Members inherited from any direct superinterfaces (§8.1.4) Members declared in the body of the class (§8.1.5) Members of a class that are declared private are not inherited by subclasses of that class. Only members of a class that are declared protected or public are inherited by subclasses declared in a package other than the one in which the class is declared. Constructors, static initializers, and instance initializers are not members and therefore are not inherited.
继承 只能继承类的属性和方法 然而 在主函数里面的只不过是对类进行的操作并不能够继承 假如这个程序这样写的话就可以继承了 public class meclass{ public void out(){ System.out.print("生物"); } } class human extends meclass {
} 在这里的human不需要任何代码 就可以使用在meclass里面定义的方法 比如 human dd = new human(); dd.out();
2:为什么要继承,省写N多代码啊!代码重用,节省开支。
3:不能继承的有最后的类和方法,即关键字final了的
那么在子类中就可以调用这个方法,只有一个语句是不可以的。
thinking in java,
特别好的一本书,如果你要英文的话,网上哪里都有,如果中文,只有第一版,翻译得很烂,建议你看英文。
他似乎连面向对象都不清楚
看JAVA思想难度高了点
看看《Java 核心技术》第一卷:基础知识吧
很简单很详细的说
也是。那先看《Java语言和面向对象程序设计》
王克宏编写的好像。
Members inherited from any direct superinterfaces (§8.1.4)
Members declared in the body of the class (§8.1.5)
Members of a class that are declared private are not inherited by subclasses of that class. Only members of a class that are declared protected or public are inherited by subclasses declared in a package other than the one in which the class is declared.
Constructors, static initializers, and instance initializers are not members and therefore are not inherited.
public class meclass{
public void out(){
System.out.print("生物");
}
}
class human extends meclass
{
} 在这里的human不需要任何代码 就可以使用在meclass里面定义的方法
比如
human dd = new human();
dd.out();
不是meclass的
记住:
类是对象的定义,对象是类的实例,
希望我的回复对你有所帮助。