|
-
Feb 12th, 2007, 02:46 AM
#1
Thread Starter
PowerPoster
[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
-
Feb 12th, 2007, 06:43 PM
#2
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.
-
Feb 12th, 2007, 09:26 PM
#3
Thread Starter
PowerPoster
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
-
Feb 12th, 2007, 09:35 PM
#4
Re: How can I use keyword “super”
super(), and it must be the first statement.
http://mindprod.com/jgloss/constructor.html
-
Feb 12th, 2007, 09:42 PM
#5
Thread Starter
PowerPoster
Re: How can I use keyword “super”
“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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|