inner class

来源:互联网 发布:2017交通安全事故数据 编辑:程序博客网 时间:2024/06/06 00:26
import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.Date;interface Machine{void run();}class persion{void run(){System.out.println("persion run");}}//当一个类继承的类和实现的接口中的方法重复时,可以用内部类去解决class robet extends persion{ class machinhear implements Machine { public void run() { System.out.println("machine run"); } }  public Machine getMachine() { return new machinhear(); }}public class testMachin {static void  meth1(A a){a.f1();}static void meth2(B b){b.f2();}static void change(Point pt){int tmp;tmp =pt.x;pt.x=pt.y;pt.y=tmp;}public static void main(String[] args) {/*robet r = new robet();Machine m = r.getMachine();m.run();r.run();*//*C c= new C();B b = c.gerb();meth1(c);meth2(b);*//*Point pt = new Point(1,2);System.out.println(pt);//Point pt1 = (Point)pt.clone();Point pt1 = pt;pt1.x=5;pt1.y=6;*///change(pt1);//System.out.println(pt);//System.out.println(pt1);/*ArrayList<Integer> arrlist = new ArrayList<Integer>();for(int i= 0; i< 5; i++){arrlist.add(new Integer(i));}System.out.println(arrlist);*/SimpleThread st = new SimpleThread();st.setName("Thread1");System.out.println(st.isAlive());SimpleThread st1 = new SimpleThread();st.start();st1.start();System.out.println(st.isAlive());System.out.println("main say");}}class SimpleThread extends Thread{public void run(){int count=0;while(count<3){System.out.println(Thread.activeCount());String name=Thread.currentThread().getName();count++;if(name.equals("Thread1")){System.out.println("good");}else{System.out.println("bye");}}}/*SimpleThread st = new SimpleThread();st.setName("Thread1");System.out.println(st.isAlive());SimpleThread st1 = new SimpleThread();st.start();st1.start();System.out.println(st.isAlive());System.out.println("main say");*/}class Point implements Cloneable{int x;int y;Date dt;Point(int x, int y){this.x=x;this.y=y;dt = new Date();SimpleDateFormat simdate = new SimpleDateFormat("yyyy");String date = simdate.format(dt);}public Object clone(){Point o =null;try{o=(Point)super.clone();o.dt =(Date)super.clone();}catch(Exception e){}return o;}public String toString(){return "x="+x +"\t"+"y="+y+"\t" +"date" + dt;}}class A{void f1(){}}abstract class B{abstract void f2();}class C extends A{B gerb(){return new B() {@Overridevoid f2() {// TODO Auto-generated method stub}};}}

原创粉丝点击