Hi all,
i want to implement something like
class B
{
public:
int b;
};
class A
{
int a;
public:
B b;
};
In this case, i have a delegate of class B in A. Can't we have such a
thing in java?
I tried doing like this:
public class B
{
public int b;
}
public class A
{
private int a;
public B b;
}
It give me error as, class B should be defined in file named B.java
Thiis too much obligation from java.
Sorry for asking such a simple question, but it is not simple for me.
Thanks in Advance
Tanveer
Chris Smith - 13 Jul 2006 19:08 GMT
> In this case, i have a delegate of class B in A. Can't we have such a
> thing in java?
Yes.
> It give me error as, class B should be defined in file named B.java
> Thiis too much obligation from java.
>
> Sorry for asking such a simple question, but it is not simple for me.
Public classes are required to be in their own source files, named after
the class. You can write the same code. It just needs to be in two
different files. This is not related to your delegation relationship,
but is rather a requirements for all public classes in Java. (It's
widely considered to be a good idea for non-public classes as well.)

Signature
Chris Smith - Lead Software Developer / Technical Trainer
MindIQ Corporation
Oliver Wong - 13 Jul 2006 19:18 GMT
> Hi all,
>
[quoted text clipped - 33 lines]
>
> Sorry for asking such a simple question, but it is not simple for me.
Create two files: one called B.java, and one called A.java. Put class B
in B.java, and put class A in A.java.
Alternatively, make one of the classes non-public.
Alternatively, nest one of the classes inside the other.
- Oliver