why do we need super() sub class constructor?

why do we need super() sub class constructor? explain it

New Member Asked on September 7, 2017 in Computer.
Add Comment
  • 1 Answer(s)

    There is an implicit call to super() with no arguments for all classes that have a parent – which is every user defined class in Java – so calling it explicitly is usually not required. However, you mayuse the call to super() with arguments if the parent’s constructor takes parameters, and you wish to specify them. Moreover, if the parent’s constructor takes parameters, and it has no default parameter-less constructor, you will need to call super() with argument(s).

    An example, where the explicit call to super() gives you some extra control over the title of the frame:

     

    class MyFrame extends JFrame



    {



    public MyFrame() {



    super("My Window Title");



    ...



    }



    }

     

     

    For More Details go to : https://stackoverflow.com/questions/10508107/why-call-super-in-a-constructor

    New Member Answered on September 8, 2017.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.