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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
   | JAVA
public class Toto {
  private String phrase;
  public Toto(String phrase) {this.phrase = phrase;}
  public void parle() { System.out.println(phrase); }
}
 
JAVA QUI RESSEMBLE A DU C
public class Toto {
  public String phrase;
 
  public static Toto createToto(String phrase) {
    Toto t = new Toto();
    t.phrase = phrase;
    return t;
  }
 
  public static void parle(Toto t) {System.out.println(t.phrase);}
}
 
C QUI RESSEMBLE A DU JAVA
struct Toto {
  char* phrase;
}
 
struct Toto* create_toto(char* phrase) {
  struct Toto* t = malloc(sizeof(struct Toto));
  t->phrase = phrase;
  return t;
}
 
void parle(Toto* t) {
  printf("s", t->phrase);
}
 
C
struct Toto {
  char* phrase;
}
 
struct Toto createToto(char* phrase) {
  Toto t;
  str_cpy(phrase, t->phrase);
  return t;
}
 
void parle(Toto t) {
  printf("s", t.phrase);
} | 
Partager