JAVA学习笔记

//建立接口,方法draw是在子类的子类(M)中实现的。
package com.czy.inter;


public interface drawcolor {
	int color = 0;
	public void draw ();
}

package com.czy.inter;

public interface Calculate {
	public final double pi = 3.1415926535;
	double gerArea(double r);
	double gerCir(double r);
}

 

建立枚举 

package com.czy.color;

public enum color {
	RED,ORANGLE,YELLO,GREEN,CYAN,BLUE,PURPLE
}

 定义抽象类集成多个接口。

package com.czy;

import com.czy.inter.Calculate;
import com.czy.inter.drawcolor;

public abstract class interExam implements Calculate, drawcolor {
	public double gerArea(double r) {
		// TODO Auto-generated method stub
		return r*r*pi;
	}

	public double gerCir(double r) {
		// TODO Auto-generated method stub
		return 2*pi*r;
	}
}

 

测试类

package com.czy;

import com.czy.color.color;;
public class M extends interExam {
	/**
	 * @param args
	 */
	color co;
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.println("test implements");
		M intertest =new M();
		double area=intertest.gerArea(1.0);
		System.out.println(area);
		double s=intertest.gerCir(1.0);
		System.out.println(s);
		intertest.draw();
	}

	public void draw() {
		System.out.println("color is " + String.valueOf(color));//这里应该怎么改,才用到枚举?
	}
}

 只是笔记,为自己做参考,也许有很多。大家就别看了。

你可能感兴趣的:(java)