inner class

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() {
				
				@Override
				void f2() {
					// TODO Auto-generated method stub
					
				}
			};
		}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值