A Package program can be saved and complied in a different way.To create directory(-d) same name as package name, to current folder(.)
In cmd.exe
E:\>javac -d . plante.java
E:\>javac -d . star.java
E:\>javac milkyway.java
E:\>java milkyway
Jupiter
69911.0
orange,white
Sun
695700.0
red,orange,yellow,green,blue,violet
In cmd.exe
E:\>javac -d . plante.java
E:\>javac -d . star.java
E:\>javac milkyway.java
E:\>java milkyway
Jupiter
69911.0
orange,white
Sun
695700.0
red,orange,yellow,green,blue,violet
- E:\
- milkyway.java
- milkyway.class
- plante.java
- star.java
- galaxy
- Categroy.class
- plante.class
- star.class
To understand this above figure.
CODING:plante.java
package galaxy;
class Categroy
{
double size;
String color;
public void set(double num,String name){size=num;color=name;}
public void get(){System.out.println(size+"\n"+color);}
}
public class plante
{
String plante;
Categroy c1=new Categroy ();
public void set(String pName,double num,String cName){
plante=pName;
c1.set(num,cName);
}
public void get(){System.out.println(plante);c1.get();}
}
star.javaclass Categroy
{
double size;
String color;
public void set(double num,String name){size=num;color=name;}
public void get(){System.out.println(size+"\n"+color);}
}
public class plante
{
String plante;
Categroy c1=new Categroy ();
public void set(String pName,double num,String cName){
plante=pName;
c1.set(num,cName);
}
public void get(){System.out.println(plante);c1.get();}
}
package galaxy;
import galaxy.Categroy;
public class star
{
String star;
Categroy c1=new Categroy ();
public void set(String Sname,double num,String cName){
star=Sname;
c1.set(num,cName);
}
public void get(){System.out.println(star);c1.get();}
}
milkyway.javaimport galaxy.Categroy;
public class star
{
String star;
Categroy c1=new Categroy ();
public void set(String Sname,double num,String cName){
star=Sname;
c1.set(num,cName);
}
public void get(){System.out.println(star);c1.get();}
}
import galaxy.plante;
import galaxy.star;
class milkyway
{
public static void main(String [] args)
{
plante p1=new plante();
p1.set("Jupiter",69911,"orange,white");
p1.get();
star s1=new star();
s1.set("Sun",695700,"red,orange,yellow,green,blue,violet");
s1.get();
}
}
import galaxy.star;
class milkyway
{
public static void main(String [] args)
{
plante p1=new plante();
p1.set("Jupiter",69911,"orange,white");
p1.get();
star s1=new star();
s1.set("Sun",695700,"red,orange,yellow,green,blue,violet");
s1.get();
}
}
Comments
Post a Comment