Java-Super to Call Superclass Method

Program Program Source class Super { void print() { System.out.println(“SuperPrint”); } } class Sub extends Super{ void print() { super.print(); System.out.println(“SubPrint”); } } public class Javaapp { public static void main(String[] args) { Sub obj = new Sub(); obj.print(); } }

Java-Super Keyword

Super Keyword In some cases, a variable in a subclass may have the same name as a super class variable. In such a case, the newly defined subclass variable hide the super class variable. In the following program, the super class Data has a variable named data1 and its value is 10. The subclass NewData … Read more…