import java.security.BasicPermission;
class SecretWordPermission extends BasicPermission {
public SecretWordPermission(String name) {
super(name);
}
public SecretWordPermission(String name, String action) {
super(name);
}
}
class SecretWord {
public SecretWord() {
super();
}
public String getWord() {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkPermission(new SecretWordPermission("AccessPermission"));
}
return "Secret";
}
}
public class MainClass {
public static void main(String[] args) {
SecretWord secret = new SecretWord();
String theSecretWord = secret.getWord();
System.out.println("The secret word is: " + theSecretWord);
}
}
|