202k views
2 votes
In Java, a reference variable is ________ because it can reference objects of types different from its own, as long as those types are related to its type through inheritance.

User Pani
by
3.8k points

1 Answer

1 vote

Answer:

polymorphic

Step-by-step explanation:

An example of polymorphic reference, suppose you have 3 classes: Main, Product and SpecificProduct. If SpecificProduct extends Product this means it is a product class but with something else to complement.

Say you want to reference an object of product in the main class, you can do it the classic way:

Product pd = new Product();

Or you can do it polymorphic, like this:

Product pd = new SpecificProduct();

The program will accept just fine because SpecificProduct is extending Product. When you do it like this, we say the reference you made was a polymorphic reference

User Aubrey Love
by
3.5k points