Whats wrong with Java's Private Membership
The code is:
Code Java:
class room
{
float z;
float y;
}
public static void main()
{
float area;
room r = new room();
r.z=10;
r.y=20;
area=r.z*r.y;
System.out.println("area = ", area);
}
Why is this giving me an answer area = 200
I know that by default member's are private so I should not be able to access the variables without creating an member function that is public.:confused:
Re: Whats wrong with Java's Private Membership
Quote:
Originally Posted by
CandorZ
I know that by default member's are private so I should not be able to access the variables without creating an member function that is public.:confused:
no, the default access means the the element is visible/accessible inside the same package. so, because the class room is in the same package like the main, also the variable x and z are visible. to be precise, the visibility of default is
from the same class: yes
from any class in the same package: yes
from a subclass in the same package: yes
from a subclass outside the same package: no
from any non-subclass class outside the package: no