| | |
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 |
3d 6 @param affinetransform android api applet application arc array arrays automation binary bluetooth bold byte c++ chat class client code color compare component coordinates database detection doctype eclipse educational error file fractal froglogic game givemetehcodez graphics gridlayout gui guitesting helpwithhomework html ide ideas image ingres input integer internet intersect j2me java java.xls javaexcel javaprojects jni jpanel jtextarea julia keytool keyword linux list loop map method methods mobile netbeans newbie nextline object pong problem producer program programming project projectideas read recursion recursive replaysolutions rim scanner sell server set size sms sort sql string swing terminal threads tree web websites windows






