Java newbie problem: classes of the same package accessing one another?

Posted by HH on Stack Overflow See other posts from Stack Overflow or by HH
Published on 2010-05-03T14:38:27Z Indexed on 2010/05/03 15:48 UTC
Read the original article Hit count: 224

Filed under:
|
|

Test.java and SetWord.java belong to the package tools. Test.java needs to access SetWord but an odd error 'cannot find' SetWord appear. The package limits the visibility, it works without 'package tools;' lines.

  1. How can I acess the SetWords with Test in the same pkg?
  2. In general, how can classes access one another in the same pkg?

Test.java

package tools;
import java.io.*;
import java.util.*;
public class Test{
    public static void main(String[] args)
    {
        //IT CANNOT FIND SetWords despite the same folder, why?
        SetWord sw=new SetWord();
        System.out.println(st.set("HELLO)");
    }
}

SetWord.java

package tools;
import java.io.*;
import java.util.*;

public class SetWord{

        public SetWord(){}
        public String set(String s)
        {       
                return s.trim().toLowerCase();
        }               
}    

© Stack Overflow or respective owner

Related posts about java

Related posts about package