31.07.2015 Views

Juin 2005

Juin 2005

Juin 2005

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

public class MystApp {public static void main(String args[]) {Myst un, deux, trois;un = new Myst(5, null);System.out.println("Question 1 "+un.toString ( ) ) ideux = new Myst(l, un);system.out.println( "Question 2 n+deux.toString(});trois = deux.ifie{new Myst(4,null)};System.out.println("Question 3 : R+trois.toString(»;un = new Myst(2, new Myst(3, new Myst(6, null»);system. out.println{"Question 4 "+Un.toString ( ) ) ;deux = trois.ifie(un);System.out.println(t1Question 5 "+deux.toString(»;}}Questions 1 à 5Indiquez ce qu'afficherait l'exécution de la commande java MystApp.Note: Nous rappelons que la méthode System.out.println affiche son argument dans la fenêtrede laquelle a été lancée la commande.L'opérateur + correspond à la concaténation de chaînes de caractères (" a "+" b" donne" ab").3 - Héritage(30 minutes)Soit les classes Java suivantespublic class A {String type;String valeur;public AC String v) {type: "A";valeur = lOO*Vi}public A f (A x) {return new A(valeur + x.valeur);}public String toString{) {return type+" e n+valeuI;}}public class B extends A { public class C extends B {public B(String V) { public C(String v) {super{v) ; super(v) ;type'" type+">B" i type = type+">C";valeur = lO*v; valeur = valeur/lOi} }public B f(B x} { public C f(C x) {returD new B(valeur + x.valeur) ; return new C(valeur+x.valeur);} }} }public class Heritage {public static void main(String args[]) {A unA new A("3");B une = new B("2");C une = new C("I");A var;}System.out.println ( "Questionvar = unA.f(new A( "4"}) iSystem.out.println("Questionvar = unB.f(unB);System.out.println("Questionvar = unB.f(unC);system.out.println("Questionvar = unB.f(unA);system.out.println("Questionvar = var.f(unC);System.out.println("Question1 "+UnC.tostring( » i2 "+var.tostring( »;3 "+Var. toString ( »;4 "+var.toString{»;5 "a-var •toString( »;6 n+var.toString()}i2

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!