JAVA easy class -- circle
- public class Circle2 {
- public static void main(String[] args) {
- Circle2 circle1 = new Circle2();
- System.out.println("radius " + circle1.radius + " Area " + circle1.getArea());
- Circle2 circle2 = new Circle2(30.0);
- System.out.println("radius " + circle2.radius + " Area " + circle2.getArea());
- circle2.radius = 40.0;
- System.out.println("radius " + circle2.radius + " Area " + circle2.getArea());
- }
- double radius;
- Circle2()
- {
- radius = 1.0;
- }
- Circle2(double dIn)
- {
- radius = dIn;
- }
- double getArea()
- {
- return radius * radius *Math.PI;
- }
- }
object and class
class is a template, blueprint that defines data fields and methods will be.
An object is an instance of a class.
留言
張貼留言