Created
July 16, 2021 15:40
-
-
Save hgfernan/d0325f1deede2eb64e4d8e7e51e758a8 to your computer and use it in GitHub Desktop.
Valid Java code, showing no access limits to encompassed classes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
*/ | |
package tPrivateProtected; | |
/** | |
* @author hilton | |
* | |
*/ | |
public class EncompassingClass { | |
static class PrivateClass { | |
private int privateMember = 0; | |
private PrivateClass() { | |
privateMember = 1; | |
} | |
private int sum(ProtectedClass pdc) { | |
return privateMember + pdc.protectedMember; | |
} | |
} | |
static class ProtectedClass { | |
protected int protectedMember = 0; | |
protected ProtectedClass() { | |
protectedMember = 1; | |
} | |
private int sum(PrivateClass pec) { | |
return protectedMember + pec.privateMember; | |
} | |
} | |
/** | |
* @param args | |
*/ | |
public static void main(String[] args) { | |
PrivateClass pec = new PrivateClass(); | |
ProtectedClass pdc = new ProtectedClass(); | |
System.out.println("Private member " + pec.privateMember); | |
System.out.println("Protected member " + pdc.protectedMember + "\n"); | |
System.out.println("Private sum: " + pec.sum(pdc)); | |
System.out.println("Protected sum: " + pdc.sum(pec)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment