I have two classes:
public class Hello
{
public static void main (String[] args)
{
Animal dog=new Animal();
dog.bark();
}
}
and
public class Animal
{
void bark()
{
System.out.println("Woof");
}
}
When I put these 2 class in a same package, it compiles successfully. But when I create a new package called "samples" and put the class Animal into the new package, I modified my code into
import samples.Animal;
public class Hello
{
public static void main (String[] args)
{
Animal dog=new Animal();
dog.bark();
}
}
and
package samples;
public class Animal
{
void bark()
{
System.out.println("Woof");
}
}
and it shows error:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method bark() from the type Animal is not visible
at Hello.main(Hello.java:8)