View RSS Feed

My Java Tips

  1. Constructor calling ordering

    by , 11-13-2011 at 11:34 AM (My Java Tips)
    Constructors are used for initialization normally. Name of constructor should be same as that of the class. If no constructor is declared, a default constructor is created without parameters. Constructor does not return any thing.


    Consider the example below. ClassB inherits from ClassA. In the MainClass, we made an object of ClassB. Default constructor will be called. But the output suggests that first Constructor of ClassA is called and then the constructor of classB is called. ...