Basic Java Language: Difference between revisions
| Line 167: | Line 167: | ||
==Public, Private - What are they?== | ==Public, Private - What are they?== | ||
These statments are used to protect data. For example, "private int myInt" will make myInt only accessible from the class it is in. Here is a complete description:<br> | These statments are used to protect data. For example, "private int myInt" will make myInt only accessible from the class it is in. Here is a complete description:<br> | ||
''' | |||
<center> | |||
{| border=1 cellspacing=0 cellpadding=5 | |||
| '''Name''' | |||
| '''Desc.''' | |||
| '''Example + Meaning''' | |||
|- | |||
| private | |||
| Variable only accessible from class it is in | |||
| private int myInt;//myInt can only be edited and viewed from the class it is in | |||
|- | |||
| | |||
| (No modifier) - only accessible from class and subclass | |||
| private int myInt;//A subclass can access it, as the class it is in | |||
|- | |||
| protected | |||
| Accessible from package, subclass, and class | |||
| private int myInt;//Class, subclass, and package classes can access it | |||
|- | |||
| public | |||
| Fully accessible | |||
| private int myInt;//Any class can access it | |||
|} | |||
</center> | |||