4
votes

So right now I have the following standard package name setup in my project:

SampleClass.java looks like this:

package main.java.model;

public class SampleClass {
    int packagePrivateMethod() {
    return -1;
    }
}

And SampleClassTest.java looks like this:

package test.java.model;

import main.java.model.SampleClass;

public class SampleClassTest extends junit.framework.TestCase {
    private SampleClass sampleClass;

    public void setUp() {
    this.sampleClass = new SampleClass();
    }

    public void test_packagePrivateMethod() {
    // this method can't be called right now why?
    //this.sampleClass.packagePrivateMethod();
    }
}

Why can't the method packagePrivateMethod() be called???

1
its not private. It has default access.Florescent Ticker
You do know that package private (default) access means that only other classes in the same package can access it?Raedwald

1 Answers

5
votes

It can't be called because the two classes are not in the same package. One is in main.java.model the other in test.java.model.