0

consider the following code

class A
 {
 Class B
  {
    ...
  }
 psvm()
  {
    B b= new A().new B(); //this one works
    B b[]=new A().new B[size]; //compile error
  }

how to go about?

1
  • @MadProgrammer,, I was thinking about hashtable implementation where the outer class is hashtable and inner class would be index nodes pointing to their respective chains,, is this correct?? btw , i didn't understand your comment... Commented Mar 13, 2015 at 3:54

2 Answers 2

3

You're creating an array of Bs. That is, you are creating a data structure that can store references to B objects. That data structure is not a B and therefore does not need an A to exist.

B b[] = new B[size];
Sign up to request clarification or add additional context in comments.

Comments

2

You can use something like...

A.B[] c = new A.B[size];

But B may need to be declared public if you want to access it from outside the context of the package it is declared...

You can also import B

import your.awesome.packages.A.B;

Which will allow you to use...

B[] c = new B[10];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.