0% found this document useful (0 votes)
32 views

Package Public Class Private Double Private Public: Radius Color

This Java code defines a Circle class with private radius and color fields. It includes default and parameterized constructors to set radius and color values. Getter methods return radius and color while getArea calculates and returns the area. Setter methods allow changing radius and color. The toString method returns a string with radius and color.

Uploaded by

Mrmr Gawad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Package Public Class Private Double Private Public: Radius Color

This Java code defines a Circle class with private radius and color fields. It includes default and parameterized constructors to set radius and color values. Getter methods return radius and color while getArea calculates and returns the area. Setter methods allow changing radius and color. The toString method returns a string with radius and color.

Uploaded by

Mrmr Gawad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Circle.

java

package Exam2;

public class Circle {


private double radius;
private String color;

public Circle() {
radius = 1.0;
color = "red";
}

public Circle(double radius, String color) {


this.radius = radius;
this.color = color;
}

public double getRadius() {


return radius;
}

public String getColor() {


return color;
}

public double getArea() {


return radius * radius * Math.PI;
}

public void setRadius(double radius) {


this.radius = radius;
}

public void serColor(String color) {


this.color = color;
}

public String toString() {


return "Circle[radius = " + radius + " color = " + color + "]";
}

Page 1

You might also like