Skip to content
Advertisement

Tag: constructor

Setter methods or constructors

so far I have seen two approaches of setting a variable’s value in Java. Sometimes a constructor with arguments is used, others setter methods are used to set the value of each variable. I know that a constructor initialises an instance variable inside a class once a class is instantiated using the “new” Keyword. But when do we use constructors

Circular dependency in Java constructors

I have the following classes. and As can be clearly seen, there is a circular dependency between the classes. if I try to run class A, I eventually get a StackOverflowError. If a dependency graph is created, where nodes are classes, then this dependency can be easily identified (at least for graphs with few nodes). Then why does the JVM

Advertisement