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
楼主【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 %
敬礼!