Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access private field without getter method?

Tags:

java

Here is an excerpt from JDK7 source code:

public String(String original) {
    this.value = original.value;
    this.hash = original.hash;
}

Both value and hash are private field. Why is original.value legal?

like image 305
Neo Avatar asked Dec 15 '22 02:12

Neo


1 Answers

See this table:

                   Access Levels
Modifier     | Class  | Package   |  Subclass | World
-------------+--------+-----------+-----------+--------
public       |   Y    |     Y     |     Y     |   Y
protected    |   Y    |     Y     |     Y     |   N
no modifier  |   Y    |     Y     |     N     |   N
private      |   Y  ← |     N     |     N     |   N    
like image 50
Maroun Avatar answered Jan 01 '23 07:01

Maroun