Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

putting classes in package  RSS feed

 
Anila Mathew
Ranch Hand
Posts: 69
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a confusion regarding how to compile classes in different packages

For example

My two classes
package certification;
public class Test
{
public int x;
}

package other;
import certification.Test;
class SubTest extends Test
{
void testIt()
{
System.out.println(x);
}
public static void main(String[] args)
{
SubTest s =new SubTest();
Test t = new Test();
System.out.println("The value of x is"+x);
s.testIt();
}
}

How should i compile these classes??
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved from SCJP
Sorry, I forgot to add [C0DE][/C0DE] brackets before moving.
[ August 30, 2004: Message edited by: Barry Gaunt ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose your current directory is c:\here.
Make two subdirectories certification and other.
Copy Test.java and SubTest.java to the subdirectories certification and other, respectively.

Make sure you are back in directory c:\here
Compile Test.java with javac -cp . certification\Test.java
Compile SubTest.java with javac -cp . other\SubTest.java

After you have sorted out the compile errors you can run your program with
java -cp . here.SubTest
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more thing 'Anila Mathew C' please conform to our JavaRanch Naming Policy by changing your displayed name to one of the formats:

<first name> <family name>
<initial of first name> <family name>
<first name> <initial of second name> <family name>

Thanks,
-Barry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!