(*** Exercice 1 ***) let cpt = object val mutable value = 0 method get_value = value method incr n = value <- value + n end;; cpt#incr 123;; class counter init_value = object val mutable value = init_value method get_value = value method incr n = value <- value + n end;; let cpt = new counter 456;; class resettable_counter init_value = object inherit counter init_value method reset = value <- 0 end;; let cqt = ((new resettable_counter 789) :> counter);; using System; class Program { public static void Main() { Console.WriteLine("Caramba !"); } } (*** Exercice 2 ***) public class Subtyping { static class SuperCat {}; static class Cat extends SuperCat {}; static class Kitty extends Cat {}; interface ISnuggleable { Cat snuggleWith(Cat other); } class Snug1 implements ISnuggleable { public Cat snuggleWith(Cat other) { return other; } } static class SuperNyan{ private T t; public SuperNyan(T ot) { ot = t; }; } static class Nyan extends SuperNyan { public Nyan(T ot) { super(ot); }; }; static class SubNyan extends Nyan { public SubNyan(T ot) { super(ot); }; }; public static void main(String[] args) { System.out.println("Java Subtyping"); Cat c = new Cat(); } } using System; class Subtyping { class SuperCat {}; class Cat : SuperCat {}; class Kitty : Cat {}; interface Snuggleable { Cat snuggleWith(Cat c); }; class Snug1 : Snuggleable { public Cat snuggleWith(Cat c) { return c; } } class SuperNyan { T x; public SuperNyan(T t) { x = t; } public void set(T y) { x=y;} public T get() { return x; } } class Nyan : SuperNyan { public Nyan(T t) : base(t) {} } class SubNyan : Nyan { public SubNyan(T t) : base(t) {} } public static void Main() { Console.WriteLine("CSharp Subtyping"); Cat c = new Cat(); } } class P implements Comparable

{ public Integer x; P(Integer x) { this.x = x; } public int compareTo(P other) { return (x.compareTo(other.x)); } } class SubP extends P { public Double y; SubP(Integer x, Double d) { super(x); this.y = d; } public int compareTo(SubP other) { if (x.compareTo(other.x) != 0) return (x.compareTo(other.x)); else return (y.compareTo(other.y)); } } (*** Exercice 3 ***)