- <P>abstract class YuanGong
- {
- private String name;
- private String gonghao;
- private int gongzi;
- void YuanGong(String name,String gonghao,int gongzi)
- {
- this.name=name;
- this.gonghao=gonghao;
- this.gongzi=gongzi;</P>
- <P> }
- public abstract void show();
-
-
-
- }
- class JingLi extends YuanGong
- {
- private int jiangjin;
- void jingli(String name,String gonghao,int gongzi,int jiangjin )
- {
- super (name,gonghao,gongzi);
- this.jiangjin=jiangjin;
-
- }
- public void show()
- {
- System.out.println(name+","+gonghao+","+gongzi+","+jiangjin);
-
- }
- </P>
- <P>}
- class Test
- {
- public static void main(String[] args)
- {
- //JingLi j=new JingLi();
- //j.name="邵阳";
- //j.show();
- JingLi j=new JingLi();
- j.jingli("shaoyang","21",900,500);
- j.show();
-
- }
- }</P>
复制代码 输出结果是:
chouxiang.java:24: 错误: 对super的调用必须是构造器中的第一个语句
super (name,gonghao,gongzi);
^
chouxiang.java:30: 错误: name可以在YuanGong中访问private
System.out.println(name+","+gonghao+","+gongzi+","+jiangjin);
^
chouxiang.java:30: 错误: gonghao可以在YuanGong中访问private
System.out.println(name+","+gonghao+","+gongzi+","+jiangjin);
^
chouxiang.java:30: 错误: gongzi可以在YuanGong中访问private
System.out.println(name+","+gonghao+","+gongzi+","+jiangjin);
^
4 个错误
第一个问题是我将变量私有,但是我没有直接从类中引用啊,为什么还出现无法访问私有。
第二个问题是我已经将super语句放在第一句啦,怎么还出现没放第一句啊。
希望给我详解答案,最好将过程一步步下下来。小弟0基础,引申一下别的更好,多学点
|
|