Accessibility and Visibility
With Examples in Java |
Prof. David Bernstein
|
Computer Science Department |
bernstdh@jmu.edu |
Block | Entity is accessible within a block of code |
Subprogram | Entity is accessible within a subprogram |
Class/Private | Entity is accessible by all entities within a class |
Generalized/Protected | Entity is accessible in its class and all extensions |
Complete/Public | Entity is accessible everywhere |
There are other types of accessibility/visibility as well, some of which we will encounter later.
+
#
-
public int length
public void paint(Graphics g)
public class String
private int size
private void recalculate()
protected String title
protected void layout()
try-catch
Statements:
try-catch
statements
can often cause difficulties
Suppose that the Signature
class contains the following
declaration:
private String email, name, saying, url;
What happens in the following application and why?
javaexamples/oopbasics/PrivateAccessibility1.java