| Author |
can someone explain me this?
|
Ankur kothari
Ranch Hand
Joined: Sep 06, 2009
Posts: 531
|
|
by providing static int x=1 what are we doing here? why is this even allowed when we aren't allowed this if x was a method..i mean int x(){} and static int x(){}
does this compile because
|
 |
Abhay Agarwal
Ranch Hand
Joined: Feb 29, 2008
Posts: 697
|
|
instance variable i gets shadowed by static variable i.
for methods, we can
a. overload them
b. override them
c. inherit them
but can not hide them
Underlying concept of this question is - Instance variable can be shadowed (Shadowing concept)
|
Oracle certified Java 7 Programmer, SCJA 1.0, SCJP 5.0, SCWCD 5.0, Oracle SQL Fundamentals I
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
please, clearly ask your question?
|
 |
Salil Vverma
Ranch Hand
Joined: Sep 06, 2009
Posts: 219
|
|
Hi Seetharaman/Abhay ,
As we can see that the above program is running fine without any issues. The question that Ankur asked is "why is this even allowed when we aren't allowed this if x was a method". The question is any thoughts why sun restricted the implementation of static method with the same name in child class but did not restrict the existance of same reference name with static qualifier?
Do you find any logical explanation of it?
Regards
Salil Verma
|
Regards
Salil Verma
|
 |
Salil Vverma
Ranch Hand
Joined: Sep 06, 2009
Posts: 219
|
|
Hi Abhay,
Could you please share some link explaining the purpose and benefits of shadowing concept.
Regards
Salil Verma
|
 |
 |
|
|
subject: can someone explain me this?
|
|
|