Hi I just wonder, if I can have construction like this:
public class MyClass
{
private int a = 5;
private AnotherClass another = new AnotherClass();
public MyClass()
{
//absolutely nothing to do in here
}
}
which lets me initialize variables directly in class definition what for do we need constructor? I always thought that we should initialize object via constructor but as java lets us do it without constructor what is the point of having one? Except of course to provide a way to tell compiler that we want another object of this class by saying:
MyClass myClass = new MyClass();
Thanks for any answers.