如何通过private关键字在父类中声明print()方法,使其在子类中不可直接访问?
- 内容介绍
- 文章标签
- 相关推荐
本文共计85个文字,预计阅读时间需要1分钟。
javaclass A { public void fun() { this.print(); }
private void print() { // 此为private,无覆盖System.out.println(这是zsd) }}
public class TestDemo { public static void main(String[] args) { B b=new B(); b.fun(); }}
class 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(); } }
本文共计85个文字,预计阅读时间需要1分钟。
javaclass A { public void fun() { this.print(); }
private void print() { // 此为private,无覆盖System.out.println(这是zsd) }}
public class TestDemo { public static void main(String[] args) { B b=new B(); b.fun(); }}
class 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(); } }

