Created
December 10, 2020 06:27
-
-
Save Riduidel/7b0ba17affe0ea57211b3cc78e9b71c7 to your computer and use it in GitHub Desktop.
Visitor -2 - Main avec interface
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
import java.util.Arrays; | |
import java.util.List; | |
class Feuille implements Affichable { | |
public String montrerFeuille() { return "🍃"; } | |
@Override public String afficher() { return montrerFeuille(); } | |
} | |
class Fleur implements Affichable { | |
public String afficherFleur() { return "🌺"; } | |
@Override public String afficher() { return afficherFleur(); } | |
} | |
interface Affichable { | |
public String afficher(); | |
} | |
public class Main { | |
public static void main(String[] args) { | |
List<Affichable> affichables = Arrays.asList(new Feuille(), new Fleur()); | |
for (Affichable affichable : affichables) { | |
System.out.println(affichable.afficher()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment