为什么父类中的print()方法要使用private声明而不是public或protected?
- 内容介绍
- 文章标签
- 相关推荐
本文共计83个文字,预计阅读时间需要1分钟。
javaclass A { public void fun() { this.print(); } private void print() { // 此为private,无覆盖 System.out.println(zhe shi zsd); }}
public class TestDemo { public static void main(String[] args) { B b=new B(); b.fun(); }}
gistfile1.txtclass A { public void fun(){ this.print(); } private void print{ //此为private,无覆写 System.out.println("zhe shi zsd") } } public class TestDemo{ public static void main(String args[]){ B b = new B(); b.fun(); } }
本文共计83个文字,预计阅读时间需要1分钟。
javaclass A { public void fun() { this.print(); } private void print() { // 此为private,无覆盖 System.out.println(zhe shi zsd); }}
public class TestDemo { public static void main(String[] args) { B b=new B(); b.fun(); }}
gistfile1.txtclass A { public void fun(){ this.print(); } private void print{ //此为private,无覆写 System.out.println("zhe shi zsd") } } public class TestDemo{ public static void main(String args[]){ B b = new B(); b.fun(); } }

