| Can access from... | default | private | protected | public |
|---|---|---|---|---|
| Same class | Yes | Yes | Yes | Yes |
| Subclass in same package | Yes | No | Yes | Yes |
| Non-subclass in same package | Yes | No | Yes | Yes |
| Subclass in different package | No | No | Yes | Yes |
| Non-subclass in same package | No | No | No | Yes |
"default" is also called package-private.
How do computers represent numbers? In binary (base 2, using 0's and 1's).
The prefix 0b indicates that the number is binary:
0b101 = 4 + 0 + 1
Why should I care, when I can just use base 10?
Additional (surplus) reading: Sections 4.1-4.6 of Dive into Systems
See worksheet for skeleton
public class PasswordChecker {
/** Returns true if the provided login and password are correct. */
public boolean authenticate(String login, String password) {
// Does some secret authentication stuff...
}
}
public class User {
private String username;
private String password;
public void login(PasswordChecker p) {
p.authenticate(username, password);
}
}
public class PasswordExtractor extends _______________PasswordChecker {
String extractedPassword;
public String extractPassword(User u) {
}
}
/** Returns whether the ith bit of num is a 1 or not. */
public static boolean isBitIOn(int num, int i) {
int mask = 1 __________________________________________;
return ________________________________________________;
}
Relevant bit operations:
x & yx << n
/** Returns the input number but with its ith bit changed to a 1. */
public static int turnBitIOn(int num, int i) {
int mask = 1 __________________________________________;
return ________________________________________________;
}
Relevant bit operations:
x | yx << n (again!)