?
Solved

polymorphic arrays and branching logic in Java

Posted on 2007-08-08
6
Medium Priority
?
634 Views
Last Modified: 2013-12-29
Hi experts,
                Can anybody tell me what are polymorphic arrays and branching logic in Java ? Thanx in advance.
0
Comment
Question by:royalcyber
  • 3
  • 2
6 Comments
 
LVL 23

Accepted Solution

by:
Siva Prasanna Kumar earned 750 total points
ID: 19653968
>> "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
 
LVL 2

Expert Comment

by:tbeernot
ID: 19654467
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
 
LVL 12

Assisted Solution

by:marklorenz
marklorenz earned 750 total points
ID: 19654557
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 23

Expert Comment

by:Siva Prasanna Kumar
ID: 19654805
@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
 
LVL 2

Expert Comment

by:tbeernot
ID: 19655086
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
 
LVL 2

Expert Comment

by:tbeernot
ID: 19655143
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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month15 days, 21 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question