Java newbie problem: package with private access

Posted by HH on Stack Overflow See other posts from Stack Overflow or by HH
Published on 2010-05-03T02:13:00Z Indexed on 2010/05/03 2:18 UTC
Read the original article Hit count: 249

Filed under:
|
|

Pack.java imports pack.TestPack; but it cannot access it. I cannot understand why it cannot access the class despite the import.

Error

Pack.java:7: TestPack() is not public in pack.TestPack; cannot be accessed from outside package
        System.out.println(new TestPack().getHello());  
                           ^
1 error

Pack.java

import pack.TestPack;
import java.io.*;

public class Pack
{
        public static void main(String[] args){
                System.out.println(new TestPack().getHello());
        }
}

TestPack.java

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

public class TestPack
{
        private String hello="if you see me, you ar inside class TestPack";
        public String getHello(){return hello;}
        TestPack(){}
}

© Stack Overflow or respective owner

Related posts about java

Related posts about package