SCJP,SCWCD,SCBCD,SCEA Part I
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Section 8.4.6.2
If a class declares a static method, then the declaration of that method is said to hide any and all methods with the same signature in the superclasses and superinterfaces of the class that would otherwise be accessible to code in the class. A compile-time error occurs if a static method hides an instance method.
Section 8.4.6.4
It is possible for a class to inherit more than one method with the same signature. Such a situation does not in itself cause a compile-time error. There are then two possible cases:
* If one of the inherited methods is not abstract, then there are two subcases:
o If the method that is not abstract is static, a compile-time error occurs.
o Otherwise, the method that is not abstract is considered to override, and therefore to implement, all the other methods on behalf of the class that inherits it. A compile-time error occurs if, comparing the method that is not abstract with each of the other of the inherited methods, for any such pair, either they have different return types or one has a return type and the other is void. Moreover, a compile-time error occurs if the inherited method that is not abstract has a throws clause that conflicts (�8.4.4) with that of any other of the inherited methods.
* If all the inherited methods are abstract, then the class is necessarily an abstract class and is considered to inherit all the abstract methods. A compile-time error occurs if, for any two such inherited methods, either they have different return types or one has a return type and the other is void. (The throws clauses do not cause errors in this case.)
Cheers, Sathya Srinivasan - SCJP 1.2, SCWCD 1.2, SCMAD 1.0
Co-Author of Whizlabs SCMAD Certification Exam Simulator and SCMAD Exam Guide Book
Originally posted by Sujatha Kumar:
Hi All,
I have read in few articles that the static methods cannot be inherited.
To prove to myself about what i have read,
I created a Parent Class with a static method say MethodA()
then i Created a Child Class inheriting the Parent Class
But It was a surprise for me when I saw that,
I was able to inherit the static method defined in the Parent Class??
Can anyone of you, share your thoughts on this topic....
Regards
[ November 10, 2004: Message edited by: Sujatha Kumar ]
Originally posted by Nikhil Vasaikar:
It can also be overridden in the child class.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Originally posted by Vladas Razas:
I think they could/should disallow this kind of shadowing in compiler. We can always chose another method name for inherited class.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
SCJP,SCWCD,SCBCD,SCEA Part I
SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
Originally posted by Ilja Preuss
No, it cannot be overridden
I've read about this kind of thing at the checkout counter. That's where I met this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|