Question: Suppose a Shape class has two descendent classes: Circle and Rectangle. If an array is declared as type Shape[], and Circle has additional functionality, how
![If an array is declared as type Shape[], and Circle has additional](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f63d3c537b9_56366f63d3bd93ad.jpg)
Suppose a Shape class has two descendent classes: Circle and Rectangle. If an array is declared as type Shape[], and Circle has additional functionality, how can you access the additional methods in Circle from a Shape element, without having the Java program crash? a. The Shape element should call its getChild() method to determine which additional methods are available in the child class O b. Call the desired method from the Shape element. If the Circle class has overriden the method then it will call the Circle classes' method, otherwise the Shape method will be called c. Use the instanceof keyword to determine if the current Shape element is actually a Circle instantiation, then cast the Shape element into a Circle to access the additional methods. O d. Create a second array of type Circle and copy each element from the Shape array into the Circle array. The additional methods can be called from the Circle objects e. Pass the current Shape element into a Circle constructor and then call the additional methods as needed
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
