老师,这里为什么会错?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | public class TestWork extends Work{ //属性:编写的测试用例个数、发现的Bug数量 private int testNum; private int bugNum; // 编写构造方法,并调用父类相关赋值方法,完成属性赋值 public TestWork() { } public TestWork(String name, int testNum, int bugNum) { super (name); this .setTestNum(testNum); this .setBugNum(bugNum); } // 公有的get***/set***方法完成属性封装 public int getTestNum() { return testNum; } public void setTestNum( int testNum) { this .testNum = testNum; } public int getBugNum() { return bugNum; } public void setBugNum( int bugNum) { this .bugNum = bugNum; } // 重写运行方法,描述内容为:**的日报是:今天编写了**个测试用例,发现了**bug。其中**的数据由属性提供 public String work() { String str1= this .getName()+ "的日报是:" + "今天编写了" + this .getTestNum()+ "个测试用例," + "发现了" + this .getBugNum()+ "bug" ; return str1; } } |
1、用super(name )为什么错?怎么改?
2、work方法中怎么获取name?
1
收起
正在回答
4回答
同学你好,this.getName()是name属性的get方法,可以根据此方法获取name的属性值。
带参构造方法中使用了this.name=name语句为属性name赋值,这里并没有使用this.getName()方法哦~同学这里的疑惑是什么呢?请详细描述下,方便老师为同学解答。
如果我的回答解决了你的疑惑,请采纳。祝:学习愉快~
1. Java 零基础入门
- 参与学习 人
- 提交作业 3802 份
- 解答问题 11489 个
本阶段带你迈入Java世界,学习Java必备基础知识,基础语法、面向对象思想以及常用工具类的使用。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧