Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Type, compile, and run listing 9.1, page 326 (file TestCircle.java). Notice that this program has 2 classes in the same file (Class TestCircle and Class

Type, compile, and run listing 9.1, page 326 (file TestCircle.java). Notice that this program has 2 classes in the same file (Class TestCircle and Class Circle). Understand how objects circle1, circle2, and circle3 are created and manipulated.

2. Now, type, compile, and run listing 9.2, page 328 (file Circle.java). Notice that the main method of this class is acting as the test class in listing 9.1. Next, make some changes to this class to create 2 more objects, say circle4 and circle5. Print out the radius and area of each circle object similar to other circle objects.image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

9.3 Example: Defining Classes and Creating Objec Classes are definitions for objects and objects are created from classes This section gives two examples of defining classes and uses the classes to creat Listing 9.1 is a program that defines the Circle class and uses it to create objects gram constructs three circle objects with radius 1, 25, and 125 and displays the r area of each of the three circles. It then changes the radius of the second object t displays its new radius and area. LISTING 9.1 TestCircle.java 1 public class TestCircle ( 2 3 public static void main(Stringt] args) f 4 5 /Main method /I Create a circle with radius 1 Circle circle1 new Circle(); System, out, println("The area of the circle of radius + circle1.radius+"is "circle1.getArea)); /I Create a circle with radius 25 System.out.println ("The area of the circle of radius" 7 10 Circle circle2 new Circle (25): + circle2.radius is" circle2.getArea()) /I Create a circle with radius 125 Circle circle3 = new Circle(125); System.out.println ("The area of the circle of radius " 12 16 +circle3.radius "is "+circle3.getArea()) /1 Modify circle radius circle2.radius = 100; // or circle2.setRadius (100) System.out.println("The area of the circle of radius " 19 20 21 + circle2.radiusis "+ circle2.getArea(); 23 24 25

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Write a note on Organisation manuals

Answered: 1 week ago

Question

Define Scientific Management

Answered: 1 week ago

Question

Explain budgetary Control

Answered: 1 week ago

Question

Solve the integral:

Answered: 1 week ago