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

 Suppose a Shape class has two descendent classes: Circle and Rectangle.
If an array is declared as type Shape[], and Circle has additional

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!