class Base{
public void Base(){
System.out.println("Base");
}
}
public class In extends Base{
public static void main(String argv[]){
In i=new In();
}
}
//why no output in runtime !
public void Base(){
System.out.println("Base");
}
}
public class In extends Base{
public static void main(String argv[]){
In i=new In();
}
}
//why no output in runtime !
System.out.println("Base");
}
}
####################################
public class In extends Base { public static void main(String[] args){
In i= new In();
}
}
################################
有结果!我看了
原来你的构造函数定义为void的了!
刚才怎么没有发现呢?
还是年轻啊!
Base(){
System.out.println("Base");
}
}
public class In extends Base{
public static void main(String argv[]){
In i=new In();
}
}
去掉void就好了
是不是构造方法 一定不能是VOID呢?
楼主的void Base()是个普通方法,所以在构造子类的时候没有去调用父类的方法。
public void Base(){
System.out.println("Base");
}
}
public class In extends Base{
public static void main(String argv[]){
In i=new In();
}
} java中的构造方法前面不能有类型,去掉void就可以了。