All code in my posts, unless a source is explicitly mentioned, is my own.
scjp6-90%
armando fonseca wrote:Hi Leonard,
I really enjoyed your example, it took me like 25 minutes to conclude the following:
First, you are not overloading, because the parameter list for both static methods are the same.
In your case, since The parameter list, the method name and return type are same for both myFun1(), what I think (not 100 percent sure), is that JVM assumes that you that are trying to override , so it then jumps to the check for an appropriate accessibility modifier ( lin other words, it jumps over the static modifier) because it seems that the access modifiers have higher priority than static/abstract/final and finds out that there is a private keyword and stops any other validation on the method's header, hence, ignoring the static context.
This is what I'm assuming, but again I understand that you want the correct answer, alright btw, Welcome to JavaRanch!
- Armando
All code in my posts, unless a source is explicitly mentioned, is my own.
Ruben Soto wrote:
armando fonseca wrote:Hi Leonard,
I really enjoyed your example, it took me like 25 minutes to conclude the following:
First, you are not overloading, because the parameter list for both static methods are the same.
In your case, since The parameter list, the method name and return type are same for both myFun1(), what I think (not 100 percent sure), is that JVM assumes that you that are trying to override , so it then jumps to the check for an appropriate accessibility modifier ( lin other words, it jumps over the static modifier) because it seems that the access modifiers have higher priority than static/abstract/final and finds out that there is a private keyword and stops any other validation on the method's header, hence, ignoring the static context.
This is what I'm assuming, but again I understand that you want the correct answer, alright btw, Welcome to JavaRanch!
- Armando
Hi Armando,
There was one time when I made similar assumptions also. Then I found out that the truth was a little different. I think my previous post in this thread explains briefly what's going on. For more details the JLS is the way to go.
scjp6-90%
All code in my posts, unless a source is explicitly mentioned, is my own.
SCJP 6 - SCWCD in progress...
Shin Kudo wrote:static methods are also inherited. I think everything which has access modifier other than private is inherited. Here is an example:
and the output is:
so in your case, it's overriding. The overriding method can not have more restrictive access modifier.
and the output is:
scjp6-90%
SCJP 6 - SCWCD in progress...
scjp6-90%
Vishal Gupta<br />------------<br />SCJA
You save more money with a clothesline than dozens of light bulb purchases. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|