| | |
java problem with creating arrays
![]() |
If both Process ID and Process Time have a common subset of operations that you can use from the array then you can have them as derived classes:
Provided you only use the common subset of methods from the array items then you can let polymorphism do the dirty work for you.
Java Syntax (Toggle Plain Text)
abstract class process_thingie { public abstract String get_thingie(); } class process_id extends process_thingie { private String id; public process_id ( String init ) { id = new String ( init ); } public String get_thingie() { return id; } // ID specific stuff } class process_time extends process_thingie { private String time; public process_time ( String init ) { time = new String ( init ); } public String get_thingie() { return time; } // Time specific stuff } public class Main { public static void main ( String[] args ) { process_thingie[] list = new process_thingie[10]; for ( int i = 0; i < 5; i++ ) list[i] = new process_id ( "id: " + i ); for ( int i = 5; i < 10; i++ ) list[i] = new process_time ( "time: " + i ); for ( int i = 0; i < 10; i++ ) { if ( i % 5 == 0 ) System.out.println(); System.out.print ( list[i].get_thingie() + "\t" ); } } }
I'm here to prove you wrong.
![]() |
Similar Threads
- Reading and creating 1d and 2d arrays (Java)
- Problem when passing arrays from c# to matlab (C#)
- problem in creating menu bar in asp.net2003 (ASP.NET)
Other Threads in the Java Forum
- Previous Thread: "String Index Out of Range" ACK!!
- Next Thread: Thinking OOP!: From BASIC to JAVA
| Thread Tools | Search this Thread |
android api applet application apps array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card chat class classes client code collision columns component constructor database designadrawingapplicationusingjavajslider draw eclipse error errors eventlistener exception expand fractal free game givemetehcodez graphics gui guidancer html ide image inetaddress integer intellij j2me java javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop machine map method methods migrate mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle plazmic print problem program programming project radio recursion scanner server set sharepoint smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads tree unlimited utility webservices windows






