-
May 22nd, 2018, 03:41 AM
#1
Overriding the constructor
Hi All,
Just wanted to know in what scenario we need to override the constructor in python?
And how to do that?
Thanks
-
May 22nd, 2018, 04:49 AM
#2
Re: Overriding the constructor
As in define a constructor in a derived class, perhaps one that invokes a base class constructor?
I'm curious what prompted this question, i.e., what made you ask this question?
-
May 22nd, 2018, 04:53 AM
#3
Re: Overriding the constructor
Yes I was also surprised. In one interview it was asked how to override a constructor. Then it came to my mind what scenario this would be useful to override the constructor.
Last edited by Rajesh78; May 22nd, 2018 at 04:55 AM.
-
May 22nd, 2018, 05:01 AM
#4
Re: Overriding the constructor
Well, then the answer should be fairly obvious: when your derived class objects need to be initialised in a way not anticipated by the base class. I'm sure you have come across such cases in other programming languages that also have native OO support.
As for the how: do you know how to write a constructor? Do you know how to use super to invoke a base class method? If not, learn how. If you do, then you have your answer.
-
May 22nd, 2018, 05:11 AM
#5
Re: Overriding the constructor
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|