can i do arrays with different classes in one class?

Recommended Answers

All 2 Replies

can i do arrays with different classes in one class?

can you be a bit clearer as to what exactly you want.

yes, you can.
by using polymorphism. if you have an array of Objects, you can use that array to store each an every Object that passes a is-a test (instanceof) of the type you declared your array for.

so:

Object[] myArray = new Object[100];

will be able to contain every kind of class (type of object, that is) that you can think of.

but if you want to have something like that, you might be better of with a collection or a list.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.