I am familier with other languages.But i am learning java now. I was reading the access modifiers . I found that only public class can be accessed from outside. And the [default] class cant not be accessed from outside. But as i have written some simple code i cam access the non public class from outside:
Add.java
class Add{
int a(int x, int y)
{
return x+y;
}
}
MyClass.java
public class MyClass {
public static void main(String args[]) {
Add obj= new Add();
int sum= obj.a(10,20);
System.out.println("Sum of x+y = " + sum);
}
}
OUTPUT>>>
Sum of x+y = 30
So please someone explain this for me? I want to know how this is happening! Thanxx in advance.