|
-
Oct 2nd, 2008, 07:51 PM
#1
Thread Starter
Addicted Member
[RESOLVED]Combining
i have two java program. lets call them javaA and javaB both are .java files. how do i import javaA into javaB.
ps
incase some people start saying i dont understand. for the sake of this lets say javaA just take the input and doubles and returns the value. now how can i use javaA in javaB
Last edited by Ebiru; Oct 6th, 2008 at 12:39 PM.
-
Oct 2nd, 2008, 08:40 PM
#2
Re: Combining
put a simple "import javaA;" at the beginning of class javaB, this will do the trick, but in case javaA is in a different folder you need to add it's path (the path of the compiled .class file) to the class-path parameter when compiling javaB
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Oct 3rd, 2008, 06:13 AM
#3
Thread Starter
Addicted Member
Re: Combining
 Originally Posted by ComputerJy
put a simple "import javaA;" at the beginning of class javaB, this will do the trick, but in case javaA is in a different folder you need to add it's path (the path of the compiled .class file) to the class-path parameter when compiling javaB
atm i cant compile but i have a few questions
1) w/ or w/o the ""
2) i think i try that before but get the error "." is missing and its in the same folder
Last edited by Ebiru; Oct 3rd, 2008 at 06:16 AM.
-
Oct 3rd, 2008, 09:04 AM
#4
Re: Combining
without the quotes.
If so, there is no reason to be getting errors, just make sure javaA is compiled before javaB
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Oct 3rd, 2008, 09:15 AM
#5
Thread Starter
Addicted Member
Re: Combining
 Originally Posted by ComputerJy
without the quotes.
If so, there is no reason to be getting errors, just make sure javaA is compiled before javaB
i get the fellowing
.java:3: '.' expected
import javaB;
-
Oct 3rd, 2008, 09:43 AM
#6
Re: Combining
class javaA.java:
Code:
public class javaA
{
public static void main(String[] args)
{
javaB b = new javaB();
System.out.println(b.add(2, 5));
}
}
class javaB.java
Code:
public class javaB
{
public int add(int a, int b)
{
return a + b;
}
}
See, an import statement is not needed if both classes are in the same package which seems to be the case here.. Sorry if I wasn't clear :P
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|