cookiemonster.java

来自「JAVA 编程思想 第四版 课后习题答案 代码全!」· Java 代码 · 共 27 行

JAVA
27
字号
// access/cookie2/CookieMonster.java
// TIJ4 Chapter Access, Exercise 4, page 227
// Show that protected methods have package access but are not public.

/* In directory Cookie2:
* //access/cookie2/Cookie.java
* //Creates a library
* package access.cookie2;
*
* public class Cookie {
*	public Cookie() {
*		System.out.println("Cookie contstructor");
*	}
*	protected void bite() { System.out.println("bite"); }
* }
*/

package access.cookie2;

public class CookieMonster {
	public static void main(String[] args) {
		Cookie x = new Cookie();
		x.bite(); // package access to protected method
	}
}

⌨️ 快捷键说明

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