Skip to content
Advertisement

Tag: super

Why does the call to a parent class constructor not call the parent’s methods that are overriden in the child class?

As shown in the code below, given a superclass Parent with a method calculate() that is called in Parent’s constructor, but also overriden in the class Child, why does the implicit call to Parent’s constructor within Child’s constructor not call Parent’s calculate() instead of Child’s calculate()? Output: I would have thought that to correctly construct a Parent object, its constructor

Where is the super reference in a Java instance method’s stack frame?

I read Bill Venner’s excellent Inside the Java Virtual Machine book, which, in Chapter 5 explores in detail, among other things, the composition of a JVM’s stack frame. (This chapter from the book also happens to be officially published here: https://www.artima.com/insidejvm/ed2/jvm8.html) Apart from this book I studied relatively much the runtime data areas of some JVM’s, especially their stack and

super.a = b instead of super(b)

I’m learning the super keyword and accidentally get this, here’s an example : The usual way to do this as in the tutorials is super(b) to reusing its parent constructor, but what is wrong with super.a = b? Answer When you write your class A like this: you overwrite the default constructor and in the line this.a = a you

Java inheritance using super keyword

I am using inheritance along with super function in my program ,but when I am extending my class it showing error message “There is no default constructor in ‘cc’. ” . This error message is coming after 1st subclass is extended and trying to make 2nd subclass. Here is the code Answer dd inherits cc, so it’ll have to call

Why can I not use “super” variable from a static context, even though “super” refers to the parent class and NOT a class instance, unlike “this”?

I’m talking java language. Variable “this”, when used inside a class, refers to the current instance of that class, which means you cannot use “this” inside a static method. But “super”, when used inside a class, refers to the superclass of that class, not an instance of the superclass, which should mean that you can use “super” inside a static

Advertisement