To expand what JamesCherill says in one line, The Java Compiler would add a default constructor if you haven't defined it and if you haven't defined a parameterised constructor either. But the moment you declare and define a parameterised constructor (and then don't define a default constructor) Java assumes that thats the only way you want your objects initialized (through parameterised const.) and wouldn't provide for a default one. This would be perfectly fine if you really do not want objects to be initialized the default way, but if you do want to allow that, you need to provide for the default constructor (thats what JC mentions).

So how to declare the default construtor?

class MyClass {
  public MyClass() {
     // default constructor defined explicitly
  }
  public MyClass (int i) {
    // parametised constructor
  }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.