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.
royalcyberAsked:
Who is Participating?
 
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
>> "polymorphic arrays"?

I hope it means something like this .

BaseClass[] bc = new BaseClass[100];
 bc = new SubClass1[100];
 bc = new SubClass2[100];

See the same base class object is used to point to all the different arrays. which have common base class.

>>"branching logic in Java"

refer

http://www.cs.rit.edu/~afb/20012/cs1/slides/javacontrol.html
0
 
tbeernotCommented:
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.
0
 
marklorenzCommented:
Check it out here:

Arrays of Subclasses
http://home.cogeco.ca/~ve3ll/jatutor5.htm

You may also benefit from checking into Groovy, which handles mixed types more flexibly:

http://groovy.codehaus.org/
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
@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. :)
0
 
tbeernotCommented:
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".
0
 
tbeernotCommented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.