Calling the base constructor in C#

Modify your constructor to the following so that it calls the base class constructor properly: public class MyExceptionClass : Exception { public MyExceptionClass(string message, string extrainfo) : base(message) { //other stuff here } } Note that a constructor is not something that you can call anytime within a method. That’s the reason you’re getting errors … Read more

Difference between Inheritance and Composition

They are absolutely different. Inheritance is an “is-a” relationship. Composition is a “has-a”. You do composition by having an instance of another class C as a field of your class, instead of extending C. A good example where composition would’ve been a lot better than inheritance is java.util.Stack, which currently extends java.util.Vector. This is now … Read more

JavaScript inheritance and the constructor property

Okay, let’s play a little mind game: From the above image we can see: When we create a function like function Foo() {}, JavaScript creates a Function instance. Every Function instance (the constructor function) has a property prototype which is a pointer. The prototype property of the constructor function points to its prototype object. The … Read more

What does ‘super’ do in Python? – difference between super().__init__() and explicit superclass __init__()

What’s the difference? SomeBaseClass.__init__(self) means to call SomeBaseClass‘s __init__. while super().__init__() means to call a bound __init__ from the parent class that follows SomeBaseClass‘s child class (the one that defines this method) in the instance’s Method Resolution Order (MRO). If the instance is a subclass of this child class, there may be a different parent … Read more