Friday, 31 May 2013

Super keyword in java

Super keyword is used to call superclass method directly into sub class.
 It is used to call constructor of the superclass in the base class.



public class Demo {

public void dowork() {
System.out.println("Printed in Superclass.");
}
}

public class Demo1 extends Demo{

public void printMethod() { //overrides printMethod in Superclass
super.printMethod();

System.out.println("Printed in Subclass");
}
public static void main(String[] args) {

Demo1 = new Demo();
s.doWork();
}

}


Aryantech India pune

No comments:

Post a Comment