孙鑫JAVA无难事第二节课

class Test
{
	public static void main(String[] args)
	{
		int i=0xffffffff;
		//int c=i<<2;
		//int c=i>>2;
		int c=i>>>2;
		System.out.println(i);
		System.out.println(Integer.toHexString(c));
		
	}
}


 

 

 

class Point
{
	int x,y;
	static int z;
	static final double PI=3.1415926;
	Point(int a,int b)
	{
//		PI=3.1415926;
		x=a;
		y=b;
	}
	
	Point()
	{
//		PI=3.1415926;
		this(1,1);	
	}
	static void output()
	{
		System.out.println("output() called");
		System.out.println(z);
//		System.out.println(x);
//		System.out.println(y);
	}
	void output(int x,int y)
	{
		output();
		z=5;
		this.x=x;
		this.y=y;
	}
	public static void main(String[] args)
	{
		Point pt1=new Point();
		Point pt2=new Point();
		
		pt1.z=5;
		pt2.z=6;
		
		System.out.println(pt1.z);
		System.out.println(pt2.z);
		//pt.output();
		//Point.output();
		//Point pt;
		//pt=new Point(3,3);
		//pt=new Point();
		//pt.output(5,5);
		//pt=new Point();
		//pt.x=10;
		//pt.y=10;
		//pt.output();
		/*Point pt2=new Point();
		//pt2.output();
		pt.x=6;
		pt2.x=7;
		System.out.println(pt.x);
		System.out.println(pt2.x);*/
		
	}
}


 

 

 

class Animal
{
	int height,weight;
	Animal(int height,int weight)
	{
//		System.out.println("animal construct");
	}
	void eat()
	{
		System.out.println("animal eat");
	}
	void sleep()
	{
		System.out.println("animal sleep");
	}
	void breathe()
	{
		System.out.println("animal breathe");
	}
}

class Fish extends Animal
{
	int height;
	Fish()
	{
		super(30,40);
		//Animal(30,40);
//		System.out.println("fish construct");
	}
	/*void breathe()
	{
//		super.breathe();
//		super.height=40;
		System.out.println("fish bubble");
	}*/
}

class Integration
{
	static void fn(Animal an)
	{
		an.breathe();
	}
	public static void main(String[] args)
	{
		//Animal an=new Animal();
		/*Fish fh=new Fish();
		Animal an;
		an=fh;
		Integration.fn(an);*/
		//an.breathe();
//		fh.height=30;
//		fh.breathe();
		Animal an=new Animal(30,40);
		Fish fh=new Fish();
		an=fh;
		/*if(an instanceof Animal)
		{
			System.out.println("an is animal's instance");
		}
		if(fh instanceof Fish)
		{
			System.out.println("fh is fish's instance");
		}*/
		if(an instanceof Fish)
		{
			System.out.println("an is fish's instance");
		}
		else
		{
			System.out.println("an isn't fish's instance");
		}
		if(fh instanceof Animal)
		{
			System.out.println("fh is animal's instance");
		}
		else
		{
			System.out.println("fh isn't animal's instance");
		}
	}
}


 

 

class Rectangle
{
	int l,w;
	int perimeter()
	{
		return 2*(l+w);
	}
	int area()
	{
		return l*w;
	}
	public static void main(String[] args)
	{
		Rectangle rect1=new Rectangle();
		Rectangle rect2=new Rectangle();
		
		rect1.l=10;
		rect1.w=5;
		System.out.println("perimeter of rect1 = "+rect1.perimeter());
		System.out.println("area of rect1 = "+rect1.area());
		
		rect2.l=6;
		rect2.w=4;
		System.out.println("perimeter of rect2 = "+rect2.perimeter());
		System.out.println("area of rect2 = "+rect2.area());
		
	}
}


 

你可能感兴趣的:(孙鑫JAVA无难事第二节课)