Results 1 to 4 of 4
- 10-15-2008, 12:01 AM #1
[SOLVED] Call method from another class name
With this code:
public class First
{
public void myFirst(){}}
The following is the CORRECT
statement used if you want to call
method myFirst() from another class
named “Second”?
a. First(myFirst);
b. Second (myFirst);
c. First.myFirst ( );
d. Second.myFirst ( );
e. The correct statement is not listed.
The answer is "e"...
What would be the actual correct statement? :confused:
Thanks."The minute you settle for less than you deserve, you get even less than you settled for." Maureen Dowd
- 10-15-2008, 12:05 AM #2
To call a non-static method in another class, you need a reference to that class.
First aRef = new First(); // create new instance and set reference
aRef.myFirst(); // call the method
If you already have a reference to that class, you don't need to create it. A reference can be passed in a method call:
public void calledMethod(First aRef) {
aRef.myFirst();
- 10-15-2008, 12:07 AM #3
what if I needed to call one that is static?
"The minute you settle for less than you deserve, you get even less than you settled for." Maureen Dowd
- 10-15-2008, 12:33 AM #4
Senior Member
- Join Date
- Aug 2008
- Posts
- 384
- Rep Power
- 5
Similar Threads
-
Need to dynamicaly get all parameters in a method call.
By DavidJohns in forum Advanced JavaReplies: 2Last Post: 05-21-2008, 07:15 AM -
Call Java Method
By hussainzim in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 05-15-2008, 07:22 AM -
cannot call private method from static method
By jon80 in forum New To JavaReplies: 3Last Post: 05-07-2008, 08:37 AM -
Call a Method Automatically
By rhm54 in forum New To JavaReplies: 4Last Post: 02-07-2008, 08:51 AM -
Unablt to call a sessionbean's business method in EJB 3.0
By amitid4forum in forum Enterprise JavaBeans (EJB)Replies: 0Last Post: 11-24-2007, 12:00 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks