欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

java缺陷:"覆盖"私有方法[Java编程思想]

程序员文章站 2022-06-07 21:24:33
...
package ploymorphism;

import static net.mindview.util.Print.*;

public class PrivateOverride {
	private void f() {	print("private f()");	}
	public static void main(String[] args) {
		PrivateOverride po = new Derived();
		po.f();
	}
}

class Derived extends PrivateOverride {
	public void f() {	print("public f()");	}
}

//output:
//private f();
 

 

相关标签: java