public class MaClasse {
.... ....
}
fichiers .java
javac
compilation
0100 1010101010
fichiers .class (bytecode)
jvm
Pokemon |
---|
- name : String ; - level : int ; - type : String ; |
+ Pokemon (name: String, level: int, type: String) + faireEvoluer() |
public class Pokemon {
private String name;
private int level;
private String type;
public Pokemon(String name, int level, String type) {
this.name = name;
this.level = level;
this.type = type;
}
...
}
Pokemon pikachu = new Pokemon("Pikachu", 20, "Électrique");
Nouvelles instances !!!!
Pokemon pikachu = new Pokemon("Pikachu", 20, "Électrique");
Objets créés
@
pikachu
Pokemon pikachu2 = pikachu;
@
pikachu2
pikachu2.faireEvoluer();
public class SuperHero{
private String name;
public SuperHero(String name){
this.name = name;
}
}
....
SuperHero batman = new SuperHero("batman");
SuperHero batmanAgain = new SuperHero("batman");
( batman == batmanAgain ) ==> false
public class SuperHero{
private String name;
public SuperHero(String name){
this.name = name;
}
public boolean equals(Object obj){
return (obj instanceof SuperHero)
&& (this.name.equals(((SuperHero) obj).name));
}
}
....
SuperHero batman = new SuperHero("batman");
SuperHero batmanAgain = new SuperHero("batman");
(batman.equals(batmanAgain)) ==> true
int monAge = 28;
int monAgeAgain = 28;
(monAge == monAgeAgain) => true
Pokemon |
---|
- name : String ; - level : int ; - type : String ; |
+ Pokemon (name: String, level: int, type: String) + faireEvoluer() |
Dresseur |
---|
- name : String ; |
+ Dresseur (name: String) |
0..*
public class Dresseur {
private String name;
private Pokemon[] pokemons;
public Dresseur(String name, Pokemon[] pokemons){
this.name = name;
this.pokemons = pokemons;
}
}
Pokemon pikachu = new Pokemon("Pikachu", 20, "Électrique");
Pokemon[] pokemonsSacha = new Pokemon[1];
pokemonsSacha[0] = pikachu;
Pokemon[] pokemonsOndine = new Pokemon[1];
pokemonsOndine[0] = pikachu;
Dresseur sacha = new Dresseur("Sacha", pokemonsSacha);
Dresseur ondine = new Dresseur("Ondine", pokemonsOndine);
class Pokemon{
public Pokemon(Pokemon exemple){
this.name = exemple.name;
this.level = level;
this.type = type;
}
}
...
Pokemon pikachu = new Pokemon("Pikachu", 20, "Électrique");
Pokemon[] pokemonsSacha = new Pokemon[1];
pokemonsSacha[0] = new Pokemon(pikachu);
Pokemon[] pokemonsOndine = new Pokemon[1];
pokemonsOndine[0] = new Pokemon(pikachu);
Dresseur sacha = new Dresseur("Sacha", pokemonsSacha);
Dresseur ondine = new Dresseur("Ondine", pokemonsOndine);