您的位置:首页 > 其它

重写的时候,构造器中调用方法容易错的问题

2013-03-27 19:45 253 查看
package com.huxin.test.overvide;

public class OverrideTest {

public static void main(String[] args) {

Son son = new Son();

// 结果是:father中a的方法 son中b的方法

}

}

class Father{

public Father(){

//c(); 这样会报错哦

a();

b();

}

private void a(){

System.out.println("father中a的方法");

}

public void b(){

System.out.println("father中b的方法");

}

}

class Son extends Father{

public Son(){

}

private void a(){

System.out.println("son中a的方法");

}

public void b(){

System.out.println("son中b的方法");

}

public void c(){

System.out.println("son中c的方法");

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐