Results 1 to 5 of 5

Thread: [RESOLVED] How can I use keyword “super”

  1. #1

    Thread Starter
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Resolved [RESOLVED] How can I use keyword “super”

    Hi all,

    One of the Java documentation I found that the keyword “super” can be use to call the original method from inside a method definition.

    Then look at the following code,


    Code:
    void addNumbers(int a, int b)
    	{
    		// process 1
    		super.addNumbers(a, b)
    		// process 2
    	}
    Let me explain it,

    On the process 1, add "a" and "b" together. On the process 2 add "a" and "b" with another int value. If I do so, is it ok. Please comment me on this.
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: How can I use keyword “super”

    That wasn't exactly clear.

    The super keyword is there to call the base class's version of an overridden function.
    Code:
    class Base
    {
      void foo() { ... }
    }
    
    class Derived
    {
      void foo() {
        // something more
        // now the base stuff:
        super.foo();
    }
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Re: How can I use keyword “super”

    Thanks.

    By the way, in a constructor method, how can I used keyword "super".
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: How can I use keyword “super”

    super(), and it must be the first statement.

    http://mindprod.com/jgloss/constructor.html

  5. #5

    Thread Starter
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Re: How can I use keyword “super”

    Thanks a lot.
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width