Link to home
Start Free TrialLog in
Avatar of mikegw
mikegw

asked on

Packages !!! Packages!

CLASSPATH=c:\

In directory c:\jtest I have a file Link.java -

package jtest;

public class Link {

   Object element;
   int    PreviousState;
   Link   next;
   static long Linkno;

   protected void finalize() { Linkno--; }

   Link() {
        element = null;
        PreviousState = 0;
        next = null;
        Linkno++;
   }

   Link(Object e1,Link n) {
        element = e1;
        next = n;
        Linkno++;
   }

   Link(Object e1) {
        element = e1;
        next = null;
        Linkno++;
   }

   Link(Object e1,int e2) {
        element = e1;
        PreviousState = e2;
        next = null;
        Linkno++;
   }
}

This compiles without any problems and has been used with a jbuilder application. The problem occurs when I try to compile the following program which imports the jtest package.

In directory c:\jdk1.2\bin I have a file: mytest.java -

import java.io.*;
import jtest.*;

public class mytest {

 static void main (String args[]) {
        Link mytest=new Link(); }

}

During compilation the following error is returned:

No Constructor matching Link() found in Class jtest.Link.
Link mytest=new Link(); }
            ^
1 error

There appears to be no problem importing jtest.Link, if CLASSPATH is altered it cannot find the package as would be expected. Why will it not find the constructor??

Can anybody Help ?
Avatar of mwibbels
mwibbels

Make your constructor public, otherwise you cannot access them from outside the package.
i think u need to public-ize ur constructors... the default (nothing) restricts it to within same package and subclasses
ASKER CERTIFIED SOLUTION
Avatar of Ravindra76
Ravindra76

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial