2013年9月10日星期二

JAVA class member variables are not declared public, then itdefaults to what is it ?

Beginner JAVA, wrote the following categories:
public class Fruit
{
public int num;
String colour;
private int price;
protected String taste;
}
eclipse outline so indicated :

then String colour looks and the other three are not the same , what is it use it ? The areas in which they can be called it ( such as another package, or a subclass , etc. ) ?
------ Solution ---------------------------------------- ----
default
------ Solution -------------------------------- ------------
total of four access modifiers : public, default ( that is not written ), protected, private, visible range from large to small .
------ For reference only -------------------------------------- -
default protected
------ For reference only -------------------------------- -------


Why displayed in the outline on the icon and protected String taste different? Or just used to distinguish the "default" and "protected", but using them is exactly the same ?
------ For reference only -------------------------------------- -
sorry I always thought it was protected in seems I must learn learning java based
------ For reference only ----- ----------------------------------


Oh, I checked , do not write , which is the default, also known as package, refer to the same package can access to this class - the other three inverted and C + + are the same.
------ For reference only -------------------------------------- -
I want to see the next answer
------ For reference only ----------------------------- ----------
upstairs misleading ah. .
default package can only be accessed by classes .
The protected can be a subclass of different packages to access , so it , protected the visible range is also larger.

没有评论:

发表评论