⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 finder25.java

📁 JAVA编程思想第四版英文原版习题答案. pdf原版的
💻 JAVA
字号:
// typeinfo/Finder25.java
// TIJ4 Chapter Typeinfo, Exercise 25, page 613
/* Create a class containing private, protected and package-access methods. 
* Write code to access these methods from outside of the class's package.
*/

/* Solution includes, in another package:
* package typeinfo.secret;
* public interface A {
*	void e();
* }
* // and:
* package typeinfo.secret;
* import static org.greggordon.tools.Print.*;
*
* class Secret implements A {
*	public void e() { println("public Secret.e()"); } 
*	void f() { println("package Secret.f()"); }
*	protected void g() { println("protected Secret.g()"); }
*	private void h() { println("private Secret.h()"); }
* }
*
* public class SecretMaker {
*	public static A makeSecret() { return new Secret();  }
* }
*/

import typeinfo.secret.*;
import java.lang.reflect.*;
import static org.greggordon.tools.Print.*;

public class Finder25 {
	public static void main(String[] args) throws Exception {
		A a = SecretMaker.makeSecret();
		println("a is of class type: " + a.getClass().getName());
		for(Method m : a.getClass().getDeclaredMethods()) {
			m.setAccessible(true);
			m.invoke(a);
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -