日期:2014-05-20  浏览次数:20736 次

[新手提问]关于父类构造函数继承的问题
public   class   branch
{
String   subName;
int   salary;
int   totalBooks;

branch(String   name,int   sa)
{
subName=name;
salary=sa;
}

void   calculateHrs()
{
totalHrs=totalBooks*2;
}

public   static   void   main(String   []   args)
{
Science   a=new   Science( "科学 ",10);
Art   b=new   Arts( "艺术 ",14);
}

}

class   Science   extends   branch(String   a1,int   b1)
{
int   t;
super(a1,b1);
t=super.calculateHrs()
System.out.println(super.subName+ "学科的总时数是: "+t);
}

class   Arts   extends   branch(String   a2,int   b2)
{
int   t;
super(a2,b2);
t=super.calculateHrs()
System.out.println(super.subName+ "学科的总时数是: "+t);
}


就是想测试一下怎么用,编译的时候一直提示错误,提示的是漏了扩号

不知道哪里出了错,希望指点.


------解决方案--------------------
class Science extends branch(String a1,int b1)?????

class是没有参数的

------解决方案--------------------
拼写有一个错误 Art b=new Arts( "艺术 ",14);  Arts 还有继承class Science extends branch(String a1,int b1) 不需要后面的参数吧!总之很多错误 还有super(a2,b2)能直接这样用吗?我还在继续找  如果你改队了 就把正确的贴出来看看!可能有的是我理解错了!
------解决方案--------------------
public class branch
{
String subName;
int salary;
int totalBooks;
int totalHrs;
public branch(String name,int sa)
{
subName=name;
salary=sa;
}

int calculateHrs()  // 没有返回类型
{
  return totalHrs= totalBooks*2;   // totalHrs 未定义
}
public static void main(String [] args)
{
Science a=new Science( "科学 ",10);
Arts b=new Arts( "艺术 ",14);
}

}

class Science extends branch
{
int t;
public Science(String a1,int b1)
{
super(a1,b1);
t=super.calculateHrs();
System.out.println(super.subName+ "学科的总时数是: "+t);
}
}

class Arts extends branch
{
int t;

public Arts(String a2,int b2)
{
super(a2,b2);
t=super.calculateHrs();
System.out.println(super.subName+ "学科的总时数是: "+t);
}
}


  给你改了下,看看吧,你上面错误太多了