Answered step by step
Verified Expert Solution
Question
1 Approved Answer
3. Figure 2 shows the class sphere whereas Figure 3 shows the test driver code for the class sphere. public class sphere { String color;
3. Figure 2 shows the class sphere whereas Figure 3 shows the test driver code for the class sphere. public class sphere \{ String color; double radius; boolean filled; public sphere(String color, double radius, boolean filled) \{ this.color = color; this.radius = radius; this. filled = filled; \} public double getArea()\{ return Math.PI*radius*radius*4; \}; public double getVolume()\{ return (4.0/3.0)*Math.PI*radius*radius*radius; \} \} Figure 2 public class test \{ public static void main(String args[]) \{ sphere s1= new sphere("red", 4 , true); System.out.println(s1.color); System.out.println(s1.radius); System.out.printin(s1.filled); System.out.printin(s1.getArea()); System.out.println(s1.getVolume()); \} \} Figure 3 3 a. Explain the encapsulation concept in OOP. b. Convert the code in Figures 2 and 3 to implement the encapsulation concept
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started