class Animal
{
int height,weight;
Animal()
{
System.out.println("Animal construct");
}
void eat()
{
System.out.println("Animal eat");
}
void sleep()
{
System.out.println("Animal sleep");
}
void breathe()
{
System.out.println("Animal breathe");
}
}
class Fish extends Animal
{
int height;
Fish()
{
System.out.println("Fish construct");
}
void breathe()
{
System.out.println("Fish bubble");
}
}
class Integration
{
public static void main(String[] args)
{
Fish fh=new Fish();
}
} 我的问题是,为什么和类同名的方法执行,而不同名的方法不执行?是因为名字,还是因为void?执行结果是:
Animal construct
Fish construct
{
int height,weight;
Animal()
{
System.out.println("Animal construct");
}
void eat()
{
System.out.println("Animal eat");
}
void sleep()
{
System.out.println("Animal sleep");
}
void breathe()
{
System.out.println("Animal breathe");
}
}
class Fish extends Animal
{
int height;
Fish()
{
System.out.println("Fish construct");
}
void breathe()
{
System.out.println("Fish bubble");
}
}
class Integration
{
public static void main(String[] args)
{
Fish fh=new Fish();
}
} 我的问题是,为什么和类同名的方法执行,而不同名的方法不执行?是因为名字,还是因为void?执行结果是:
Animal construct
Fish construct
解决方案 »
- 怎么获取一组图片
- Java 中如何实现倒计时?
- 求救:如何在一段Java程序(A)中执行一外部Java应用程序(ExternalB),并在A执行到特定条件下终止该外部程序B!
- String和StringBuffer 里的串连接问题!
- Java代码后面加许多个;;;;;;能通过还能运行
- [请教]为什么有些方法可以直接写,不用加对象名或类名
- 求助-关于Applet使用JNI
- tomcat5.0 怎么去掉启动的时候的提示???
- 那里有中文的API,SUN的哪个我可是看不懂
- java 中的堆栈溢出问题如何解决??请各位高手救小弟一把!!!!
- 为什么我的JDK会出现这样的情况:
- 跪求 JCombofBox 解决方案,高手进!!!!
楼主【dino_liuyu】截止到2008-07-14 16:22:19的历史汇总数据(不包括此帖):
发帖的总数量:2 发帖的总分数:40 每贴平均分数:20
回帖的总数量:8 得分贴总数量:5 回帖的得分率:62%
结贴的总数量:2 结贴的总分数:40
无满意结贴数:0 无满意结贴分:0
未结的帖子数:0 未结的总分数:0
结贴的百分比:100.00% 结分的百分比:100.00%
无满意结贴率:0.00 % 无满意结分率:0.00 %
敬礼!