Posted by: Sourav | April 21, 2015

A Package example in Java


Make a folder called test package,create 2 sub folder under it named test1 and test2.

Create  a.java under test1

a.java contains

package test1;

public class a{
public int i=2;

public static void main(String args[])

{
//static int i=2;
System.out.println(“Hello”);
}

}

Create a b.java under test2

package test2;
import test1.a;

class b{
int k=90;
public static void main( String args[])
{
a A=new a();

int j=35;
System.out.println(A.i);
}
}

Now in cmd go to test packages folder

javac test1\a.java

java test1.a

javac test2\a.java

java test2.b

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: