How to invoke the super constructor in Python?

In line with the other answers, there are multiple ways to call super class methods (including the constructor), however in Python-3.x the process has been simplified: Python-3.x class A(object): def __init__(self): print(“world”) class B(A): def __init__(self): print(“hello”) super().__init__() Python-2.x In python 2.x, you have to call the slightly more verbose version super(<containing classname>, self), which … Read more

When to use an interface instead of an abstract class and vice versa?

I wrote an article about that: Abstract classes and interfaces Summarizing: When we talk about abstract classes we are defining characteristics of an object type; specifying what an object is. When we talk about an interface and define capabilities that we promise to provide, we are talking about establishing a contract about what the object … Read more

How should I have explained the difference between an Interface and an Abstract class?

I will give you an example first: public interface LoginAuth{ public String encryptPassword(String pass); public void checkDBforUser(); } Suppose you have 3 databases in your application. Then each and every implementation for that database needs to define the above 2 methods: public class DBMySQL implements LoginAuth{ // Needs to implement both methods } public class … Read more

Ruby: kind_of? vs. instance_of? vs. is_a?

kind_of? and is_a? are synonymous. instance_of? is different from the other two in that it only returns true if the object is an instance of that exact class, not a subclass. Example: “hello”.is_a? Object and “hello”.kind_of? Object return true because “hello” is a String and String is a subclass of Object. However “hello”.instance_of? Object returns … 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

Implements vs extends: When to use? What’s the difference?

extends is for extending a class. implements is for implementing an interface The difference between an interface and a regular class is that in an interface you can not implement any of the declared methods. Only the class that “implements” the interface can implement the methods. The C++ equivalent of an interface would be an … Read more

What are the rules for calling the base class constructor?

Base class constructors are automatically called for you if they have no argument. If you want to call a superclass constructor with an argument, you must use the subclass’s constructor initialization list. Unlike Java, C++ supports multiple inheritance (for better or worse), so the base class must be referred to by name, rather than “super()”. … Read more

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