Polymorphism in Java is Select one: a.when a program uses several different types of objects, each with its own variable. b.when a single variable is used with several different types of related objects in a program. c.when a single parent class has many child classes   The following code fragment is polymorphic: for(Shape shape : shapes) if(shape instanceof Circle) { Circle c = (Circle) shape; // cast to a circle c.draw(g); // call the circle's draw method } else if(shape instanceof Rect) { Rect r = (Rect) shape; r.draw(g); }   True or False   The following code fragment is polymorphic: for(Shape shape : shapes) shape.draw(g)   True or False

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter11: Advanced Inheritance Concepts
Section: Chapter Questions
Problem 2GZ
icon
Related questions
Question

Polymorphism in Java is

Select one:
a.when a program uses several different types of objects, each with its own variable.
b.when a single variable is used with several different types of related objects in a program.
c.when a single parent class has many child classes
 

The following code fragment is polymorphic:

for(Shape shape : shapes) if(shape instanceof Circle) { Circle c = (Circle) shape; // cast to a circle c.draw(g); // call the circle's draw method } else if(shape instanceof Rect) { Rect r = (Rect) shape; r.draw(g); }
 
True or False
 

The following code fragment is polymorphic:

for(Shape shape : shapes) shape.draw(g)
 
True or False
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Data members
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT