+ -
当前位置:首页 → 问答吧 → 子类继承父类,麻烦看一下这段代码怎么改,并说明下原因,谢谢

子类继承父类,麻烦看一下这段代码怎么改,并说明下原因,谢谢

时间:2011-12-24

来源:互联网

class A
{
  public A(int x)
  {}
}
class B extends A
{
  public B()
  {}
}
public class C
{
  public static void main(String[] args)
  {
  B b=new B();
  }
}

作者: zxdgxd2009   发布时间: 2011-12-24


class A
{
  public A(int x)
  {}
}
class B extends A
{
  public B(int x)
  {
  super(x);
  }
}
public class C
{
  public static void main(String[] args)
  {
  B b=new B(x);
  }
}

作者: zhourrr1234   发布时间: 2011-12-24

class A
{
int b;

public A(int x)
{
this.b = x;
}
public int getB()
{
return b;
}
}
class B extends A
{
public B(int x)
{
super(x);
}
}
public class C
{
public static void main(String[] args)
{
B b=new B(3);
System.out.println(b.getB());
}

是不是这样?

作者: ECJAN   发布时间: 2011-12-24

热门下载

更多