java访问权限控制问题
创建两个包:debug和debugoff,它们都包含一个相同的类,该类有一个debug()方法。第一个版本显示发送给控制台的string参数,而第二个版本什么也不做。使用...
创建两个包:debug和debugoff,它们都包含一个相同的类,该类有一个debug()方法。第一个版本显示发送给控制台的string参数,而第二个版本什么也不做。使用静态import语句将该类导入到一个测试程序中,并示范条件编译效果。
展开
3个回答
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");
}
} ///:~
/****************** 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");
}
} ///:~
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
有源代码吗?不太明白您表述。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你这是要源代码,还是理论解答?请详细描述!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询