CSCI 201L Final Spring 2014 13% of Course Grade
CSCI 201L Final Spring 2014 13% of Course Grade
CSCI 201L Final Spring 2014 13% of Course Grade
Spring 2014
13% of course grade
1. Inheritance - Explain the difference between an abstract class that only contains
abstract methods and an interface. Why would a programmer choose to use an
abstract class that only contains abstract methods instead of an interface? (1.0%)
2. Subnetting – A USC student called his ISP to inquire about getting a set of static IP
addresses for his new business. The technician on the line was a UCLA alumnus who
told him, “I can give you the following class C address with a subnet mask:
219.135.45.0/22.” Does this make sense? If so, what is the range of IP addresses on
the network? How many hosts can be on the network? (2.0%)
Start
1
Ready
2 3
8 7
Running
6 4
Waiting 5 Sleeping
Dead
// code block #1
class PiggyBank {
private int balance = 0;
public int getBalance() {
return balance;
}
public synchronized void deposit(int amount) {
int newBalance = balance + amount;
try {
Thread.sleep(1);
} catch (InterruptedException ie) {
System.out.println("IE: " + ie.getMessage());
}
balance = newBalance;
}
}
// code block #2
class PiggyBank {
private int balance = 0;
private Lock lock = new ReentrantLock();
public int getBalance() {
return balance;
}
public void deposit(int amount) {
lock.lock();
try {
int newBalance = balance + amount;
Thread.sleep(1);
balance = newBalance;
} catch (InterruptedException ie) {
System.out.println("IE: " + ie.getMessage());
} finally {
lock.unlock();
}
}
}
import java.util.concurrent.Semaphore;
0: 3
2: 2
5: 1
6: 1
8: 0
9: 0
4: 0
3: 0
7: 0
1: 0
5 done: 3
2 done: 1
0 done: 3
9 done: 2
8 done: 0
6 done: 2
3 done: 1
4 done: 2
1 done: 2
7 done: 3