// FIRST
PACKAGE OWN it contains the only one class ACCESS
package own;
public class access
{
private int a=10;
int b=20;
protected int c=30;
public int d=40;
public access()
{
System.out.println("A="+a);
System.out.println("B="+b);
System.out.println("C="+c);
System.out.println("D="+d);
}}
//second package OTHER which importing
the FIRST PACKAGE OWN
//OTHER PACKAGE contains two classes OACCESS,OACCESS1
package other;
public class oaccess extends own.access
{
public oaccess()
{
System.out.println("I AM DERRIVED
CLASS IN OTHER PACKAGE");
System.out.println("C="+c);
System.out.println("D="+d);
}}
package
other;
public class oaccess1 extends own.access
{
public oaccess1()
{
own.access o=new own.access();
System.out.println("I AM NON
DERRIVED CLASS IN OTHER PACKAGE");
System.out.println("D="+d);
}}
//THIS IS THE CONTRALLER CLASS WHICH
USES THE ALL ABOVE PACKAGE CLASSES
import other.oaccess;
import other.oaccess1;
import own.access;
public class otherpack
{public static void main(String
args[])
{
access a=new access();
oaccess o=new oaccess();
oaccess1 o1=new oaccess1();
}}
E:\jit1>
save all the above 4 classes here like the noramal java programs
access.java
oaccess.java oaccess1.java otherpack.java
E:\jit1>javac -d . access.java
E:\jit1>javac -d . oaccess.java
E:\jit1>javac -d . oaccess1.java
The above classes compalation u must
compile with –d . otherwise they
will compile but not available to the other classes
E:\jit1>javac otherpack.java
E:\jit1>java otherpack
A=10
B=20
C=30
D=40
A=10
B=20
C=30
D=40
I AM DERRIVED CLASS IN OTHER PACKAGE
C=30
D=40
A=10
B=20
C=30
D=40
A=10
B=20
C=30
D=40
I AM NON DERRIVED CLASS IN OTHER
PACKAGE
D=40
కామెంట్లు లేవు:
కామెంట్ను పోస్ట్ చేయండి