因为JAVA不支援类别的多程继承
所以请教各位大大要怎么样
才能用JAVA做基因演算法
从父母那一边去继承的双方各一半的基因阿!!

解决方案 »

  1.   

    用内部类呢
    class Father {
    String gene = "f";
    class Mother {
    String gene = "m";
    }
    }
      

  2.   

    恩!
    谢谢大大
    我去试试看(因为我才刚摸JAVA不久)
      

  3.   

    关于这个全部继承的问题我觉得应该还有个自定义继承机制吧
    自己再写个算法来选择继承父母双方各一半基因
    因为关于这个问题即使java支持多继承不也一样是全部继承下来的吗
      

  4.   


    public class Human {
      private final String gene;
      private final Human father;
      private final Human mother;  public static final Human ADAM = new Human("ATCGAATTCGATCCGG");
      public static final Human EVE = new Human("ATCGTTATGGTTGGCC");  // FOR Adam & Eve
      private Human(String gene) {
        this.gene = gene;
        this.father = null;
        this.mother = null;
      }  public Human(Human father, Human mother) {
        this.father = father;
        this.mother = mother;
        char[] geneArray = new char[father.gene.length];
        for (int i = 0; i < gene.length; i++) {
          gene[i] = random() ? father.gene.charAt(i) : mother.gene.charAt(i);
        }
        this.gene = new String(geneArray);
      }
    }