- class Ticket
- {
- static int ticket = 100;
- Ticket t = new Ticket();
- static void sale()
- {
- System.out.println("ticket num is :" + ticket--);
- }
- public static void main(String[] args)
- {
- //当用对象调用sale()时,出现StackOverflowError,栈溢出错误
- new Ticket().sale();
- //而当直接使用静态的方式,直接调用sale()时,就不报错,?
- //sale();
- }
- }
复制代码 |