CMSC 132A Lecture 13: Super Keyword
Document Summary
If your method overrides one of its superclass"s methods, you can invoke the overridden method through the use of the keyword super . You can also use super to refer to a hidden field (although hiding fields is discouraged). Consider this class, superclass : public class superclass { public void printmethod() { Here is a subclass, called subclass , that overrides printmethod() : public class subclass extends superclass { // overrides printmethod in superclass public void printmethod() { super. printmethod(); System. out. println("printed in subclass"); public static void main(string[] args) { Within subclass , the simple name printmethod() refers to the one declared in. So, to refer to printmethod() inherited from superclass , subclass must use a qualified name, using super as shown. The following example illustrates how to use the super keyword to invoke a superclass"s constructor. Recall from the bicycle example that mountainbike is a subclass of bicycle .