Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2006

Tip: Looking for answers? Try searching our database.

Delegation handling in java

Thread view: 
bravetanveer - 13 Jul 2006 18:34 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.