|
发表于 2015-1-6 19:24:52
|
显示全部楼层
- //第一题
- package pakage20150106;
- public class Point {
- protected int x;
- protected int y;
- public Point()
- {
- x=0;
- y=0;
- }
- public Point(int m_x,int m_y) {
- x=m_x;
- y=m_y;
- }
- public void setPoint(int m_x,int m_y) {
- x=m_x;
- y=m_y;
- }
- public int getX() {
- return x;
- }
- public int getY() {
- return y;
- }
- }
复制代码- package pakage20150106;
- public class Circle extends Point{
- final double pi=3.141592653;
- protected int radius;
- public Circle() {
- x=0;
- y=0;
- radius=0;
- }
- public Circle(int m_x,int m_y,int m_radius)
- {
- x=m_x;
- y=m_y;
- radius=m_radius;
- }
- public int getRadius() {
- return radius;
- }
- public void setRadius(int radius) {
- this.radius = radius;
- }
- public double area() {
- return pi*radius*radius;
-
- }
- }
复制代码- package pakage20150106;
- import org.junit.Test;
- public class Text {
- @Test
- public void f() {
- Circle a=new Circle(1, 2, 3);
- System.out.println("Y值为:"+a.getY());
- System.out.println("半径为:"+a.radius);
- System.out.println("面积为:"+a.area());
- a.setRadius(23);
- System.out.println("面积为:"+a.area());
- a.setPoint(3, 4);
- System.out.println("Y值为:"+a.getY());
- }
- }
复制代码
|
|