public class ClassA {
    int size;
    private ClassB someB;
    ClassA(int size){
        this.size = size;
        this.someB = null;
    }
    void methodOfA(ClassB g){
        someB = g;
        someB.somethingC = new ClassC("aaa");
    }
}

public class ClassB {
    ClassC somethingC;
    ClassB(ClassC anInitialC) {
        somethingC = anInitialC;
    }
}

public class ClassC {
    String name;
    private ClassA lastA;
    ClassC(String name){
        this.name=name;
        this.lastA = null;
    }
    void methodOfC(ClassA g){
        lastA = g;
        lastA.methodOfA(null);
    }
    void anotherMethodOfC(){
        if(lastA !=null)
        lastA.methodOfA(null);
    }
}

public class ClassD {
    public static void main(String[] args) {
        System.out.println("Hello world!");
        ClassA a1 = new ClassA(4);
        ClassC c1 = new ClassC("abc");
        ClassB b1 = new ClassB(c1);
       a1.methodOfA(b1);
       c1.methodOfC(a1);
  }
}