title: Check two objects of different classes
body: <p>I have three classes: </p>
  
  <ol>
  <li>Human </li>
  <li>Father </li>
  <li>Child.</li>
  </ol>
  
  <p>Child class extends Father and Father extends Human. </p>
  
  <p>I have created some instances of each class and stored them into a ArrayList. </p>
  
  <p>Now I want to write a method to check if object father1 has the same field address(for example: "21 str Goodwin") as the Object child1 address field (instances of class Father and Child) and give this method to my ArrayList and print if any results was found.</p>
  
  <p>How can I do this?</p>
  
  <p>Let me add my code here for more clarity:</p>
  
  <p>Human class:</p>
  
  <pre><code>  public class Om {
    String nume;
    String prenume;
    String cnp;
  
  Om(String nume,String prenume,String cnp){
  this.nume=nume;
  this.prenume=prenume;
  this.cnp=cnp;
  
  }
  @Override
  public String toString() {
      return "Numele omului: " + this.nume +"\n"+ "Prenumele omului: " + this.prenume   +"\n"+ "Cnp-ul omului: " + this.cnp + "\n" ;
  }
  
  
  }
  </code></pre>
  
  <p>Father class:</p>
  
  <pre><code>public class Parinte extends Om{
  String domiciliu;
  Parinte(String nume, String prenume, String cnp, String domiciliu){
      super(nume,prenume,cnp);
      this.domiciliu=domiciliu;
  }
  
  @Override
  public String toString() {
      return "Numele parintelui: " + nume +"\n"+
              "Prenumele parintelui :" + prenume +"\n"+ 
              "Cnp-ul parintelui: " + cnp +"\n"+ 
              "Domiciliul parintelui: "+domiciliu+"\n"; 
  }
  
  }
  </code></pre>
  
  <p>Child class:</p>
  
  <pre><code>public class Copil extends Parinte {
  int varsta;
  Copil(String nume, String prenume, String cnp, String domiciliu, int varsta){
      super(nume,prenume,cnp,domiciliu);
      this.varsta=varsta;
  }
  @Override
  public String toString() {
      return "Numele copilului: " + nume +"\n"+
              "Prenumele copilului :" + prenume +"\n"+ 
              "Cnp-ul copilului: " + cnp +"\n"+ 
              "Domiciliul compiluiui: "+ domiciliu +"\n"+
               "Varsta copilului: "+varsta+"\n";
  }
  
  
  }
  </code></pre>
  
  <p>My method to sort list alphabetical:</p>
  
  <pre><code>import java.util.*;
  
  public class comparareNume implements Comparator&lt;Om&gt;{
  public int compare(Om om1, Om om2){
      return om1.nume.compareTo(om2.nume);}
  
  
  }
  </code></pre>
  
  <p>And my main class:</p>
  
  <pre><code>import java.util.*;
  public class main {
  
  public static void main(String[] args) {
      Om om1=new Om("Dubolari", "Dragos", "2006004034120");
      Om om2=new Om("Andronachi","Andrei", "12591295967123");
      Parinte p1=new Parinte("Vreascu","Andy","5845289564684","Al. Cel Bun 13");
      Copil c1 = new Copil("Mamaliga","George","5942356874156","Al. Cel Bun 13", 15);
      List&lt;Om&gt; colectie = new ArrayList&lt;Om&gt;();
      colectie.add(om1);
      colectie.add(p1);
      colectie.add(c1);
      colectie.add(om2);
  
      comparareNume comparNume = new comparareNume();
      Collections.sort(colectie, comparNume);
      System.out.println(colectie);       
      }
  
  
  }
  </code></pre>