标题: 一道有助于理解封装的习题 [打印本页] 作者: JOKER0819 时间: 2015-8-29 22:48 标题: 一道有助于理解封装的习题 public class StackDemo{
private LinkedList<Object> list;
StackDemo(){
list = new LinkedList<Object>();
}
public void myAdd(Object obj){
list.addFirst(obj);
}
public Object myGet(){
return list.removeFirst();
}
public boolean isNull(){
return list.isEmpty();
}
}
public class LinkedListStack {
public static void main(String[] args) {
StackDemo sd = new StackDemo();
sd.myAdd("java01");
sd.myAdd("java02");
sd.myAdd("java03");
sd.myAdd("java04");