Question
There exists a Switch class that stores two objects, of the same class and is used to get the objects in alternating order. Currently this
There exists a Switch class that stores two objects, of the same class and is used to get the objects in alternating order. Currently this class is implemented by storing data using the Object class however, this requires a lot of casting by however will import the Switch class.
1a. Design a new Switch class that does not use explicit casting when getting objects. This answer should include a small section of code that shows how this class could be initialised and used to store 2 String objects.
1b. We only want this class to store objects that are subclasses of the List class. How do we update the Switch class to achieve this?
1c. Make a checked exception that is raised when the Switch class is going to return a null object.
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