Link to home
Start Free TrialLog in
Avatar of royalcyber
royalcyber

asked on

polymorphic arrays and branching logic in Java

Hi experts,
                Can anybody tell me what are polymorphic arrays and branching logic in Java ? Thanx in advance.
ASKER CERTIFIED SOLUTION
Avatar of Siva Prasanna Kumar
Siva Prasanna Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tbeernot
tbeernot

Polymophic means: can contain different kinds of objects. So an array defined as having Objects (in Java) can contain Strings and Numbers mixed.

Branching logic are the if and select statements.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@tbeernot

>> Polymophic means: can contain different kinds of objects. So an array defined as having Objects (in Java) can contain Strings and Numbers mixed.

I don't think thats polymorphic whats so great about a object array containing different object, how can you use that array, you may land up getting many exception like ClassCastExcpetion, ArrayStorageException etc etc. when you are trying to extract those objects out of the array.  

If i am wrong experts please correct me. :)
I am sorry, but an polymorphic array is one that contains multiple objects. And yes, it is tricky to work with and that is why they added generics to Java 1.5 (to improve it, still not perfect). No one said polymorphic meant "no problems".
Strange points division.

You realize that Number, Strings and any other class in java (BaseClass, SubClass)  is a subclass of Object? Hence an array of Objects can contain instances of any class.