1.匿名内部类格式
interface inte{ int n=0; public void md(); } public class Niming { public static void main(String[] args) { new inte(){ @Override public void md() { for(int i=0;i<10;i++){ System.out.println("少时诵诗书"); } } }.md(); } }
2.多线程
class A implements Runnable { int num=10; @Override public void run() { // TODO Auto-generated method stub synchronized(this){ System.out.println(Thread.currentThread().getName()+"卖了第"+num+"张票"); num--; } System.out.println("========="); } } public class Kelasi { public static void main(String[] args) { A a=new A(); new Thread(a,"t1").start(); new Thread(a,"t2").start(); new Thread(a,"t3").start(); new Thread(a,"t5").start(); new Thread(a,"t6").start(); new Thread(a,"t7").start(); new Thread(a,"t8").start(); new Thread(a,"t9").start(); new Thread(a,"t10").start(); } }