Skip to content

Instantly share code, notes, and snippets.

@radustoenescu
Created June 19, 2013 21:39
Show Gist options
  • Save radustoenescu/5818361 to your computer and use it in GitHub Desktop.
Save radustoenescu/5818361 to your computer and use it in GitHub Desktop.
import java.util.ArrayList;
import java.util.LinkedList;
public class Main {
public static void main(String[] args) {
MyStack s = new MyStack();
}
}
class Person {
private static final int DEAD_AGE = 100;
int age;
String name;
public Person(String name) {
this.name = name;
}
public void birthday(){
System.out.println("Happy birthday");
if (age < DEAD_AGE)
age++;
}
public void makeBaby() {
age = 0;
}
}
abstract class Weapon {
private String name;
protected int range, speed, power, rechargeTime;
public Weapon(String name) {
this.name = name;
}
public abstract void fire();
}
class BFG extends Weapon {
public BFG() {
super("BFG");
range = 100;
speed = 1;
power = 1000;
rechargeTime = 2;
}
public void fire(){
System.out.println(power + " * Kaboom !");
}
public void bfgKillAll(){
System.out.println("BFG extra juice");
}
}
public class Hero {
private Weapon hpn;
// composition
private String name;
public Hero(String name) {
this.name = name;
}
public void shoot() {
// delegation
hpn.fire();
}
}
class MyStack extends LinkedList {
public boolean isEmpty(){
return isEmpty();
}
public void push(Object o) {
add(o);
}
public Object pop(){
return removeLast();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment