| | |
how to call a method defined in another file?
![]() |
•
•
Join Date: Sep 2006
Posts: 162
Reputation:
Solved Threads: 14
The class calling the method needs a reference to the other class. For example, ClassA instantiates ClassB (Below) and ClassB needs to call a method provided by ClassA. The 'this' keyword can be passed into ClassB's constructor to provide it with a reference to ClassA.
E.g.
E.g.
Java Syntax (Toggle Plain Text)
public class ClassA{ ClassB subordinate; public static void main(String[] args){ subordinate = new ClassB(this); } public void mymethod(){ //do something } } public class ClassB{ ClassA master; public ClassB(ClassA master){ this.master = master; master.mymethod(); } }
Last edited by Cerberus; Jun 16th, 2007 at 4:00 pm.
The ProgrammersTalk Community | Programming & Marketing | Buying & Selling Script
Hang out place of novice and intermediate programmers
Hang out place of novice and intermediate programmers
![]() |
Similar Threads
- Safe Array (C++)
- How to call Client.java from HTML? (Java)
- Error: uncaught exception: Permission denied to call method XMLHttpRequest.open (HTML and CSS)
- Generic method parser / invoker (C#)
- How can i call my FileOutput method to output the array ?? really confused... (Java)
Other Threads in the Java Forum
- Previous Thread: Java Code for interesting Java Game
- Next Thread: Beginner Help
| Thread Tools | Search this Thread |
2dgraphics 3d @param affinetransform android api apple applet application arc arguments array arrays automation banking binary binarytree bluetooth chatprogramusingobjects class client code color compare component count database derby design detection eclipse eclipsedevelopment encryption error fractal game givemetehcodez graphics gridlayout gui guitesting helpwithhomework html ide if_statement image integer interface j2me java java.xls javadesktopapplications javaprojects jni jpanel julia keytool keyword linux list macintosh map method methods mobile netbeans object open-source os pong problem producer program project projectideas property read recursion reference replaysolutions rim scanner server set size sms sort sql stop string swing terminal threads transforms tree ui unicode validation web windows






