Question: Why is the following code, which assumes is a subclass of Question, considered poor strategy? if ( q instanceof ChoiceQuestion ) { / / Do

Why is the following code, which assumes
is a subclass of
Question,
considered poor strategy?
if (q instanceof ChoiceQuestion)
{
// Do the task the ChoiceQuestion way
}
else if (q instanceof Question)
{
}
// Do the task the Question way
should be the subclass, not the other way around.
the instanceof reserved word should only be used in a class constructor.
should not be used for type tests that can be solved by using polymorphism.
is not an operator but rather a method.
Why is the following code, which assumes is a

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 Programming Questions!