When do I use super()?

Calling exactly super() is always redundant. It’s explicitly doing what would be implicitly done otherwise. That’s because if you omit a call to the super constructor, the no-argument super constructor will be invoked automatically anyway. Not to say that it’s bad style; some people like being explicit. However, where it becomes useful is when the … Read more

python multiple inheritance passing arguments to constructors using super

Well, when dealing with multiple inheritance in general, your base classes (unfortunately) should be designed for multiple inheritance. Classes B and C in your example aren’t, and thus you couldn’t find a proper way to apply super in D. One of the common ways of designing your base classes for multiple inheritance, is for the … Read more

Getting the name of a sub-class from within a super-class

Don’t make the method static. The issue is that when you invoke getClass() you are calling the method in the super class – static methods are not inherited. In addition, you are basically name-shadowing Object.getClass(), which is confusing. If you need to log the classname within the superclass, use return this.getClass().getName(); This will return “Entity” … Read more

Java: Calling a super method which calls an overridden method

The keyword super doesn’t “stick”. Every method call is handled individually, so even if you got to SuperClass.method1() by calling super, that doesn’t influence any other method call that you might make in the future. That means there is no direct way to call SuperClass.method2() from SuperClass.method1() without going though SubClass.method2() unless you’re working with … Read more

Why is Python 3.x’s super() magic?

The new magic super() behaviour was added to avoid violating the D.R.Y. (Don’t Repeat Yourself) principle, see PEP 3135. Having to explicitly name the class by referencing it as a global is also prone to the same rebinding issues you discovered with super() itself: class Foo(Bar): def baz(self): return super(Foo, self).baz() + 42 Spam = … Read more

Is it unnecessary to put super() in constructor?

Firstly some terminology: No-args constructor: a constructor with no parameters; Accessible no-args constructor: a no-args constructor in the superclass visible to the subclass. That means it is either public or protected or, if both classes are in the same package, package access; and Default constructor: the public no-args constructor added by the compiler when there … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)