Home Creating an array of subclasses of a class
Reply: 0

Creating an array of subclasses of a class

user675 Published in May 20, 2018, 9:57 am

I'm trying to store all subclasses of A which are constructed by super() in the array child (in this case B). All the children are in the same package. This is my approach but I don't know how the class could store itself inside an array or pass itself as argument to super().

class A {
  static int i = 0;
  A[] child = new A[10]
  int someval;
  A(int val){
    someval = val;
    child[i] = ???;
class B extends A{

Is this even Possible? With my approach B will only be added when a new B() is created? Is it possible to get a complete array without creating a new object?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.304359 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO