Consider the following code: public class DemoClass{ private double PI = 3.1416; void calculateArea(double radius){ double area = PI*radius*radius; System.out.println("Area: " + area); } public static void main(String []args){ calculateArea(5.0); } } a) Suggest modification to the code so that the value of PI cannot be modified later. Also modify the above code so that it can run without any error. b) Create a non-static inner class inside the DemoClass. Move the calculateArea() function inside the inner class. Now call the calcualteArea() function from the main() function.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter13: Overloading And Templates
Section: Chapter Questions
Problem 10PE
icon
Related questions
Question
Question 1 (2 + 3) [CO1]
Consider the following code:
public class DemoClass{
private double PI = 3.1416;
void calculateArea(double radius){
double area = PI*radius*radius;
System.out.println("Area: " + area);
}
public static void main(String []args){
calculateArea(5.0);
}
a) Suggest modification to the code so that the value of PI cannot be modified later. Also modify the above code so
that it can run without any error.
b) Create a non-static inner class inside the DemoClass. Move the calculateArea() function inside the inner class.
Now call the calcualteArea() function from the main() function.
Transcribed Image Text:Question 1 (2 + 3) [CO1] Consider the following code: public class DemoClass{ private double PI = 3.1416; void calculateArea(double radius){ double area = PI*radius*radius; System.out.println("Area: " + area); } public static void main(String []args){ calculateArea(5.0); } a) Suggest modification to the code so that the value of PI cannot be modified later. Also modify the above code so that it can run without any error. b) Create a non-static inner class inside the DemoClass. Move the calculateArea() function inside the inner class. Now call the calcualteArea() function from the main() function.
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning