Here is sample code for building
a singleton pattern that returns a single instance
of a ship:
interface Const {
final static double lPI = 3;
}
interface AC {
final static double PI = Math.PI;
}
interface HST extends AC, Const{
public void fireThrusters();
public void firePhotonTorpedos();
public int kpm();
}
class Fleet {
Ship s = Ship.getShip();
}
final class Ship implements HST{
private static Ship s = new Ship();
double PI2= 2 * PI;
int v = 0;
int photonTorpedos = 10;
private Ship(){}
public static Ship getShip() {
return s;
}
public void fireThrusters() {
v++;
}
public void firePhotonTorpedos() {
photonTorpedos--;
}
public int kpm() {
return 10-photonTorpedos;
}
}
public class TrivialApplication {
public static void main(String args[]) {
System.out.println( "Hello World!" );
}
}
|