Exemple37_ScopeRetourTélécharger Exemple theorique du scope des attributs en Java (voir cours sur la syntaxe en Java) Exemple37.java // Exemple theorique du scope des attributs en Java // (voir cours sur la syntaxe en Java) import pkgX.*; import pkgY.*; public class Exemple37 { public static void main(String... args) { System.out.println("Execution de Scope"); Mere m = new Mere(); Fille f = new Fille(); A a = new A(); FilleIndigne fi = new FilleIndigne(); E e = new E(); System.out.println("Pas d'erreur d'execution"); } } compil.bat mkdir bin del /f /s /q bin\*.class javac -d bin -classpath "." *.java pause pkgX A.java package pkgX; public class A { public A() { Mere m = new Mere(); int n; n = m.x_public; //n = m.x_private; // x_private has private access in pkgX.Mere n = m.x_protected; n = m.x_default; } } Fille.java package pkgX; public class Fille extends Mere { public Fille() { Mere m = new Mere(); int n; n = m.x_public; //n = m.x_private; // x_private has private access in pkgX.Mere //n = x_private; // x_private has private access in pkgX.Mere n = m.x_protected; n = x_protected; n = m.x_default; n = x_default; } } Mere.java package pkgX; public class Mere { public int x_public; private int x_private; protected int x_protected; int x_default; public Mere() { x_private = 100; } public int getXPrivate() { return x_private; } } pkgY E.java package pkgY; import pkgX.*; public class E { public E() { Mere m = new Mere(); int n; n = m.x_public; //n = m.x_private; // x_private has private access in pkgX.Mere //n = m.x_protected; // x_protected has protected access in pkgX.Mere //n = m.x_default; // x_default is not public in pkgX.Mere; cannot be accessed from outside package } } FilleIndigne.java package pkgY; import pkgX.*; public class FilleIndigne extends Mere { public FilleIndigne() { Mere m = new Mere(); int n; n = m.x_public; //n = m.x_private; // x_private has private access in pkgX.Mere //n = x_private; // x_private has private access in pkgX.Mere //n = m.x_protected; // x_protected has protected access in pkgX.Mere n = x_protected; //n = m.x_default; // x_default is not public in pkgX.Mere; cannot be accessed from outside package //n = x_default; // x_default is not public in pkgX.Mere; cannot be accessed from outside package } } run.bat cd bin java -classpath "." Exemple37 pause