CCB Premier Import

This commit is contained in:
Christian Cunat-Brulé
2018-07-23 10:52:48 +02:00
commit f55475a23f
765 changed files with 209793 additions and 0 deletions

4
04-SOURCES/A.java Normal file
View File

@@ -0,0 +1,4 @@
public class A {
public int a ;
}

19
04-SOURCES/B.java Normal file
View File

@@ -0,0 +1,19 @@
public class B extends A {
public int b ;
public static void main(String[] args) {
A objetA = new A();
B objetB = new B();
System.out.println(objetA.a);
// ERREUR DE COMPILATION :
// "b cannot be resolved or is not a field
//System.out.println(objetA.b);
System.out.println(objetB.b);
System.out.println(objetB.a);
}
}

12
04-SOURCES/Cercle.java Normal file
View File

@@ -0,0 +1,12 @@
class Cercle extends Forme {
int rayon ;
void afficher () {
System.out.println ("x = " + x + " , y = " + y + ", couleur = " + couleur +
" rayon = " + rayon);
}
void agrandir (int facteur) {
rayon = rayon * facteur ;
}
}

33
04-SOURCES/Dessin.java Normal file
View File

@@ -0,0 +1,33 @@
class Dessin {
public static void main (String args[]) {
// Cr<43>er une forme et un cercle
Forme f = new Forme();
f.x = 10 ;
f.y = 20 ;
Cercle c = new Cercle ();
c.x = 30 ;
c.y = 50 ;
c.rayon = 100 ;
// Afficher leurs attributs avec un println
System.out.println("Affichage avec println : ");
System.out.println("Forme : " + f.x + " - " + f.y);
System.out.println("Cercle : " + c.x + " - " + c.y + "-" + c.rayon);
// Appeler la m<>thode afficher sur une instance de la classe Forme
System.out.println("Affichage avec l'appel de la m<>thode afficher() : ");
f.afficher();
// Appeler la m<>thode afficher sur une instance de la classe Cercle :
// Cette m<>thode est HERITEE !
// On peut appeler cette m<>thode sur des instances des sous-classes
// de la classe Forme
c.afficher();
}
}

View File

@@ -0,0 +1,8 @@
public class DessinResolutionAppel {
public static void main (String args[]) {
Forme f ;
f = new Cercle();
f.afficher();
}
}

11
04-SOURCES/Forme.java Normal file
View File

@@ -0,0 +1,11 @@
public class Forme {
int x ;
int y ;
int couleur ;
void afficher () {
System.out.println ("x = " + x + " , y = " + y + ", couleur = " + couleur);
}
}

View File

@@ -0,0 +1,35 @@
public class TestInstanceOf {
public static void main(String[] args) {
Forme f ;
f = new Forme ();
if (f instanceof Forme)
System.out.println ("f instance de Forme ") ;
if (f instanceof Cercle)
System.out.println ("f instance de Cercle ") ;
Forme c ;
c = new Cercle () ; // Permis grace au polymorphisme !
if (c instanceof Forme)
System.out.println ("c instance de Forme") ;
if (c instanceof Cercle)
System.out.println ("c instance de Cercle ") ;
// Appel d'une m<>thode sp<73>cifique de la sous-classe
if (c instanceof Cercle) {
// on fait un downcasting pour rassurer le compilateur
((Cercle) c).getRayon ();
}
}
}