Bidirectional reference to parent package in Java

10 views Asked by At

I'm trying to setup a java project with following structure:

[Project]
 -parent_class
 -Package
    -child_class

Importing and refrencing the child_class in the parent_class is no problem so far. The reference from parent_class to child_class seems to be difficult to implement.

Is there any way to access the parent_class from the child_class without packaging and importing the class via filepath (i.e. like you would add and import a 3rd party libary) ?

parent_class:

import Package.child_class;

public class parent_class
{
    private child_class cl;
    
    public parent_class(){
        this.cl = new child_class(this);
    }
    
}

child_class:

package Package;

public class child_class
{
    private parent_class pc;
    
    public child_class(parent_class p_pc){
        this.pc = p_pc;
    }
    
}
0

There are 0 answers