Instance variables go on stack and objects go on heap and object references go on stack. Right? But what if an instance variable was a reference to an object? Like var c:
class clony implements Cloneable {
clony c = new clony();
@Override
protected Object clone() throws CloneNotSupportedException {
return super.clone();
}
}
class tst2 {
public static void main(String[] args) throws CloneNotSupportedException {
clony j1 = new clony();
}
}
And if it goes on heap why it throws and stack overflow error?