Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

super keyword

807599Apr 27 2007 — edited Apr 27 2007
i have a couple of question about the below code.

is it possible to call the SuperClass's printMethod from the main method in the subclass? Or can the SuperClass's printMethod only be called by using the super keyword from the subclass's printMethod?
class Superclass {

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

//Here is a subclass, called Subclass, that overrides printMethod().
 
class Subclass extends Superclass {

	void printMethod() { 	//overrides printMethod in Superclass.

        super.printMethod();    
        System.out.println("Printed in Subclass.");
	
    	}

    	public static void main(String[] args) {
    	
    	Subclass s = new Subclass();
    	s.printMethod();
	
	}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 25 2007
Added on Apr 27 2007
10 comments
244 views