0

For example
Class A does not have a default constructor.
Class B extends A

Any reason/benefits to do this?

public class B extends A
{
   public B()
   {
      super();
   }
}
3
Contributors
4
Replies
5
Views
12 Years
Discussion Span
Last Post by proghelper
0

All classes have a default constructor. If it's not present, then it's implicit.

The call to super is also implicit if it's not present. The benifit of calling super is good design practice. Each constructor calls it's super class until it reaches the top of the heiarchy(most likey Object class).

Calling super() yourself just means that the JVM won't have to worry about doing all that themeselves.

0

Ahh I see.
So it’s good design practice.
If this is done throughout a large program, would this have a positive impact on performance?
Since the JVM won’t have to worry about it.

Thanks

0

No not really. I don't think there's a performance hit at all, but it's excellent practice to include that call, and even I do it. I know I don't have to, but I do it anyway.

0

Yes it is the best practice to provide the default constructor in the program code that we write.

If we do not write one, the compiler includes a default one into the byte code. However there is no gaurentee that performance wise it is faster.

Having our own constructor is not really a place where we got to bother of performance as Java is slow anyway :cheesy:

______________________________________

Programming ( Assignment / Project ) Help

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.