CariDotMy

 Forgot password?
 Register

ADVERTISEMENT

View: 2176|Reply: 3

nak mintak tlg

[Copy link]
Post time 30-7-2007 11:24 PM | Show all posts |Read mode
  • Two classes named Animal and LandAnimal
    are defined as below:

Animal
Attribute
Reply

Use magic Report


ADVERTISEMENT


 Author| Post time 30-7-2007 11:37 PM | Show all posts
lpe lak..sape2 yg baik n terer tu leh x tlg slesaikan.. aku x phm laa nak wat menda ni..
Reply

Use magic Report

Post time 2-8-2007 06:39 AM | Show all posts
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() {
        System.out.println("Printed in Superclass.");
    }
}

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

    public 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();        
    }

}

Within Subclass, the simple name printMethod() refers to the one declared in Subclass, which overrides the one in Superclass. So, to refer to printMethod() inherited from Superclass, Subclass must use a qualified name, using super as shown. Compiling and executing Subclass prints the following:
Printed in Superclass.
Printed in Subclass


rujuk: http://java.sun.com/docs/books/tutorial/java/IandI/super.html

[ Last edited by  alusmetai at 2-8-2007 06:41 AM ]

Rate

1

View Rating Log

Reply

Use magic Report

 Author| Post time 2-8-2007 10:48 PM | Show all posts
thanks alusmetai..i very appreciate it..
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

 

ADVERTISEMENT



 

ADVERTISEMENT


 


ADVERTISEMENT
Follow Us

ADVERTISEMENT


Mobile|Archiver|Mobile*default|About Us|CariDotMy

3-1-2025 12:45 AM GMT+8 , Processed in 0.337966 second(s), 21 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

Quick Reply To Top Return to the list