aspose file tools*
The moose likes Java in General and the fly likes Calling a javabean method from another javabean in the same package. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Calling a javabean method from another javabean in the same package." Watch "Calling a javabean method from another javabean in the same package." New topic
Author

Calling a javabean method from another javabean in the same package.

rita mistry
Greenhorn

Joined: Dec 04, 2001
Posts: 27
Hi all,
OK just so you know what I'm talking about....
I have a package called myPackage, in which there are two javabeans.
myBeanA and myBeanB. In myBeanA there are two methods called myMethodA and myMethodB.
In myBeanB there is a method called myMethodC.
(I hope your with me so far)
Can anyone tell me how to call the method myMethodA from myBeanA and use it in myBeanB in myMethodC.
I hope you know what I'm going on about. Any help on this subject will be very much appreciated.
Many Thanks,
Rita.
Roy Ben Ami
Ranch Hand

Joined: Jan 13, 2002
Posts: 732
are the methods static?
do u have a refernce to the other bean in BeanA ?
rita mistry
Greenhorn

Joined: Dec 04, 2001
Posts: 27
Hi,
If you mean do I have the following statement in my code:

then the answer is no. When I include it I just get errors.
I have not referenced the other bean in Bean A. Do I just input the following:

Kind Regards,
Rita.
Roy Ben Ami
Ranch Hand

Joined: Jan 13, 2002
Posts: 732
no u dont have to have the main method.
thats not what i meant.
the problem is, that in order to call a method in another class u need to have an object of that class.
so for example in you beanB class u need to create an object of BeanA.
thats not very good though and not what u want i guess.
another way is to make the methodA and methodB of BeanA static. in that case u can use in BeanB thsoe methods by typing:
BeanA.MethodA().
hope thats what u wanted.
rita mistry
Greenhorn

Joined: Dec 04, 2001
Posts: 27
Hi Roy,
Ok making method A and B static sounds good. Just one thing - How do I do this? I don't know Java that well (as you may have already guessed).
Rita.
Roy Ben Ami
Ranch Hand

Joined: Jan 13, 2002
Posts: 732
just put the word static in front of the method.
however , u should know that making a method static means that it belongs to the class, thus all objects share that method.
exapmle:
rita mistry
Greenhorn

Joined: Dec 04, 2001
Posts: 27
Hi Roy,
Good news - it works!!!
I just want to say a very big THANK YOU. I really couldn't have done it without you.
I am really really grateful. Thank you very much.
Kind Regards,
Rita.
Roy Ben Ami
Ranch Hand

Joined: Jan 13, 2002
Posts: 732
you are most welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calling a javabean method from another javabean in the same package.
 
Similar Threads
accessing protected methods from non-derived classes
Old Chestnut: Protected Access
Finding an object reference
Should this class implement Serializable ?
Passing a value from Javascript to JSP