java访问权限控制问题

创建两个包:debug和debugoff,它们都包含一个相同的类,该类有一个debug()方法。第一个版本显示发送给控制台的string参数,而第二个版本什么也不做。使用静态import语句将该类导入到一个测试程序中,并示范条件编译效果。

第1个回答  2015-08-10
//: access/debug/E03_Debug.java
/****************** Exercise 3 ****************
* Create two packages: debug and debugoff,
* containing an identical class with a debug()
* method. The first version displays its String
* argument to the console, the second does nothing.
* Import the class into a test program
* using a static import line, and demonstrate
* the conditional compilation effect.
***********************************************/
package access.debug;
public class E03_Debug {
public static void debug(String msg) {
System.out.println("Message: " + msg);
}
} ///:~
//: access/debugoff/E03_Debug.java
package access.debugoff;
public class E03_Debug {
public static void debug(String msg) {}
} ///:~
//: access/E03_DebugApp.java
package access;
import static access.debug.E03_Debug.*;
public class E03_DebugApp {
public static void main(String[] args) {
debug("DEBUG VERSION");
}
} /* Output:
Message: DEBUG VERSION
*///:~
//: access/E03_ReleaseApp.java
package access;
import static access.debugoff.E03_Debug.*;
public class E03_ReleaseApp {
public static void main(String[] args) {
debug("RELEASE VERSION");
}
} ///:~
第2个回答  2013-04-24
有源代码吗?不太明白您表述。
第3个回答  2013-04-23
你这是要源代码,还是理论解答?请详细描述!
相似回答