Bonjour,

J'ai cet exercice en Java :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
public class Test
{
static void show(int i) 
{
     System.out.println(" méthode 1 " + i) ;
}
static void show(char c) 
{
     System.out.println("méthode 2 " + c) ;
}
static void show(double d) 
{
     System.out.println("méthode 3 " + d) ;
}
static void show (String s)
{
     System.out.println("méthode 4 " + s) ;
}
static void show(Participante b)
{
     System.out.println("méthode 5 " + b) ;
}
public static void main(String[] args)
{
   Object x = "Natacha";
   String y = "Natacha";
   //show((Participante)y) ; // erreur compilation POURQUOI INCONVERTIBLE? 
   show((Participante)x) ; // erreur Interpréteur 
}
}
Pourquoi la ligne 27 ne se compile pas alors que la 28e se compile ?

Message d'erreur :
Test.java:26: error: inconvertible types
show((Participante)y) ; // erreur compilation POURQUOI INCONVERTIBLE?
^
required: Participante
found: String
1 error
Merci d'avance pour votre aide.