| | |
how to call a method defined in another file?
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
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 |
android api applet application array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) calculator chat class classes client code columns component constructor database designadrawingapplicationusingjavajslider draw eclipse editor error errors event eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress input integer intellij j2me java javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia link linux list loop map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle parsing plazmic print problem program programming project recursion scanner screen server set sharepoint size smart sms smsspam sort sortedmaps sql string subclass support swing threads time tree unlimited webservices windows






