java继承问题

wdz9804 2004-11-22 08:53:16
public abstract class Person{
public Person(){}
public Person(String userName){
this.userName = userName;
}
private String userName = "";
}

public class Manager extends Person{
public Manager(){}
public Manager(String userName,String userSalary)
try{
//数据库连接 Connectin conn =?
//查询结果集 ResultSet rs =?
// select userSalary from user where userName= "+ userName +"";
//取出薪水 正常
this.userSalary = rs.getFloat(1);
super(userName);
//释放连接
}catch(SQLException ex){
}
private float salary = 0.f;
}
问题:
super(userName)的时候,为什么编译通不过
我怀疑是不是当和数据库操作的时候,有可能出现异常的时候,所以不能够初始化父类
不知道理解的对不对, 如果是,该如何处理,如果不是,有时什么原因造成的?
...全文
92 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
VRC 2004-11-22
  • 打赏
  • 举报
回复
楼上正确!
vjanev 2004-11-22
  • 打赏
  • 举报
回复
没错,super语名必须放在构造方法的第一句。。
fmzbj 2004-11-22
  • 打赏
  • 举报
回复
this.userSalary 是在哪声名的?参数里的userSalary这个是不能用this调用的
super(userName)必须是方法中的第一条语句

public Manager(String userName,String userSalary)
try{

super(userName);

//数据库连接 Connectin conn =?
//查询结果集 ResultSet rs =?
// select userSalary from user where userName= "+ userName +"";
//取出薪水 正常
this.userSalary = rs.getFloat(1);
// super(userName);
//释放连接
}catch(SQLException ex){
}
kivin 2004-11-22
  • 打赏
  • 举报
回复
楼上正确!
caiyi0903 2004-11-22
  • 打赏
  • 举报
回复
同意楼上
liusoft 2004-11-22
  • 打赏
  • 举报
回复
super(userName)必须是方法中的第一条语句

http://www.javayou.com

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧