刚学java,有些地方很不明白,看代码:
class A
{
int i; A(int xx)
{
i=xx;
}
}class B extends A
{}public class Demo
{
public static void main(String args[])
{
B a=new B(1);
}
}
编译时不通过,提示:
Demo.java:40: 找不到符号
符号: 构造函数 B(int)
位置: 类 B
B a=new B(1);难道java中不能继承构造函数吗?
class A
{
int i; A(int xx)
{
i=xx;
}
}class B extends A
{}public class Demo
{
public static void main(String args[])
{
B a=new B(1);
}
}
编译时不通过,提示:
Demo.java:40: 找不到符号
符号: 构造函数 B(int)
位置: 类 B
B a=new B(1);难道java中不能继承构造函数吗?
class A{
int i;
A(int xx){
i=xx;
}
}
class B extends A{
B(int i){
super(10);
}
}
public class Constructor {
public static void main(String[] args) {
// TODO Auto-generated method stub
B a=new B(1);
}
}