多态 传值的一个问题
package poly;
class Glyph{
void draw(){
System.out.println("Glyoh.draw()");;
}
Glyph(){
System.out.println("Glyph() before draw()");
draw();
System.out.println("Glyph() after draw()");
}
}
class RoundGlyph extends Glyph{
private int radius = 1;
public RoundGlyph(int i) {
// TODO Auto-generated constructor stub
radius = i;
System.out.println("RoundGlyph.RoundGlyph().radius = "+radius);
}
void draw(){
System.out.println("RoundGlyph.draw().radius = "+radius); //这里为什么输出的是0,不太懂。怎么会是0呢
}
}
public class PolyCjonstructors {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new RoundGlyph(5);
}
}
class Glyph{
void draw(){
System.out.println("Glyoh.draw()");;
}
Glyph(){
System.out.println("Glyph() before draw()");
draw();
System.out.println("Glyph() after draw()");
}
}
class RoundGlyph extends Glyph{
private int radius = 1;
public RoundGlyph(int i) {
// TODO Auto-generated constructor stub
radius = i;
System.out.println("RoundGlyph.RoundGlyph().radius = "+radius);
}
void draw(){
System.out.println("RoundGlyph.draw().radius = "+radius); //这里为什么输出的是0,不太懂。怎么会是0呢
}
}
public class PolyCjonstructors {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new RoundGlyph(5);
}
}
...全文
相关推荐
C++常量引用传值优势[项目源码]
文章首先指出,使用传值方式传递参数时,编译器会创建一个临时对象,这个过程中会调用构造函数来构造临时对象,并在临时对象生命周期结束时调用析构函数进行销毁。
winform 委托窗体传值.zip
在这个"winform 委托窗体传值.zip"项目中,我们关注的是如何在WinForm窗体之间传递数据,特别是通过使用`Action`委托。
多态:Scala中的多态值
多态值多态值是那些可以接受多种类型参数的对象或函数。在Scala中,这种概念主要体现在方法和类的定义上。
详解C++值多态中的传统多态与类型擦除
在上面的例子中,如果每个指令都需要创建和删除对象,这可能导致性能问题。为了解决这个问题,可以使用类型擦除技术,将不同类型的对象包装在一个通用的类中,提供统一的接口。
一个经典c#多态的范例
在编程领域,多态性(Polymorphism)是面向对象编程的一个核心概念,它允许我们使用一个接口来代表多种不同的类型。


Java SE
