Results 1 to 9 of 9
- 01-13-2013, 01:55 PM #1
Member
- Join Date
- Jan 2013
- Posts
- 6
- Rep Power
- 0
- 01-13-2013, 02:15 PM #2
Re: How do I link a class into another class?
By implement I assume you mean you want to execute a method in Class2.implement the code in Class2
The way to execute code in another class is to get a reference to an instance of the class and use it:One way to get a reference to another class use the new statement:Java Code:refToClass2.methodInClass2(); // call a method in Class2
Java Code:Class2 refToClass2 = new Class2(<The args here>);
If you don't understand my response, don't ignore it, ask a question.
- 01-13-2013, 02:56 PM #3
Member
- Join Date
- Jan 2013
- Posts
- 6
- Rep Power
- 0
- 01-13-2013, 03:34 PM #4
- 01-13-2013, 03:46 PM #5
Member
- Join Date
- Jan 2013
- Posts
- 6
- Rep Power
- 0
Re: How do I link a class into another class?
So in that case, refToClass2 is just like the variable name?
- 01-13-2013, 04:12 PM #6
Re: How do I link a class into another class?
refToClass2 is the variable name.refToClass2 is just like the variable name?If you don't understand my response, don't ignore it, ask a question.
- 01-13-2013, 08:23 PM #7
Member
- Join Date
- Dec 2012
- Posts
- 42
- Rep Power
- 0
Re: How do I link a class into another class?
i dont want to hijack this thread but i actually have a question about the answer given,
i thought in the example Class2 refToClass2 = new Class2 , this creats a Class2 object right? so refToClass2 is an object name? or is it still considered a variable that refrences the object?
once again sorry i kinda hijacked the thread with my own question
Russ
-
Re: How do I link a class into another class?
refToClass2 is a Class2 variable that after refers to a Class2 object after the constructor call. You could assign it to null on the next line, and it is still a Class2 variable, but just one that does not refer to any object.
- 01-13-2013, 09:42 PM #9
Member
- Join Date
- Dec 2012
- Posts
- 42
- Rep Power
- 0
Similar Threads
-
Class example not compiling Runner class and Swimmer class
By Joshsmith in forum New To JavaReplies: 1Last Post: 12-13-2012, 03:06 AM -
could not find or load main class | cannot manually locate class file
By Holden Caulfield in forum New To JavaReplies: 1Last Post: 11-29-2012, 09:46 AM -
Eclipse Compile Error: Call validateValue(Class<T>, String, Object, Class<?>...)
By Tomshi in forum EclipseReplies: 0Last Post: 03-27-2011, 05:49 AM -
how to send a link through action class in struts
By Kadiyala in forum New To JavaReplies: 0Last Post: 02-17-2011, 07:44 AM -
How to create main class link to another two class?
By pearllymary78 in forum New To JavaReplies: 6Last Post: 07-16-2008, 11:02 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks