package mypg;
import java.util.*;
public class Geometric {
private String color = "white";
private Date dateCreated;
public Geometric()
{
dateCreated = new Date();
}
public Geometric (String color)
{
this.color = color;
}
public void setColor(String color)
{
this.color = color;
}
public String getColor()
{
return this.color;
}
public Date getDate()
{
return dateCreated;
}
}
+++++++++++++++++++++++++++++++
package mypg;
public class Circle extends Geometric{
private double radius;
public Circle (double radius)
{
this.radius = radius;
}
public Circle(double radius,String color)
{
this.radius = radius;
setColor(color);
}
public double getArea()
{
return radius * radius * Math.PI;
}
}
+++++++++++++++++++++++++++++++++
package mypg;
public class Test {
public static void main(String[] args) {
Geometric geo1 = new Geometric();
System.out.println(geo1.getColor()+" ; "+geo1.getDate());
Circle cir1 = new Circle(4);
cir1.setColor("red");
System.out.println(cir1.getColor()+ " ; " +cir1.getDate() + " ; " +cir1.getArea());
}
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น