From 4bb589407493b16020c1c70f7acc34be6396521d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20MARQUET?= <72651575+BreizhHardware@users.noreply.github.com> Date: Fri, 5 Sep 2025 16:34:16 +0200 Subject: [PATCH] Obisidian vault auto-backup: 05-09-2025 16:34:16 on macbook-air-de-felix. 1 files edited --- ISEN/JAVA/CIPA4/Java Cours 1.md | 46 +++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/ISEN/JAVA/CIPA4/Java Cours 1.md b/ISEN/JAVA/CIPA4/Java Cours 1.md index c639178..77e0381 100644 --- a/ISEN/JAVA/CIPA4/Java Cours 1.md +++ b/ISEN/JAVA/CIPA4/Java Cours 1.md @@ -215,18 +215,60 @@ public enum Color ## Héritage Déclaration d'un héritage ```java +public class Point +{ + private int x; + private int y; + public setX(int x) + { + this.x = x; + } + public setY(int y) + { + this.y = y; + } + public Point(x, y) + { + this.setX(x); + this.setY(y); + } +} + public class Forme { protected Point centre; - public void afficher(){ System.out.println("Je suis une forme de centre " + centre); } + public void afficher() + { + System.out.println("Je suis une forme de centre " + this.centre); + } + public void setCentre(Point centre) + { + this.centre = centre; + } + public Forme(Point centre) + { + this.setCentre(centre); + } } public class Cercle extends Forme { + private float rayon; + @Override //permet de préciser qu’une méthode est une surcharge public void afficher() { - System.out.println("Je suis un cercle de centre " + centre.toString()); + super.afficher(); + System.out.println("Je suis un cercle de rayon " + this.rayon); } + public void setRayon(float rayon) + { + this.rayon = rayon; + } + public Cercle(Point centre, float rayon) + { + super(centre); + this.setRayon(rayon); + } } ```