File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can someone explain me this?

 
Ankur kothari
Ranch Hand
Posts: 531
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 1375
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please, clearly ask your question?
 
Salil Vverma
Ranch Hand
Posts: 255
Hibernate Oracle Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Salil Vverma
Ranch Hand
Posts: 255
Hibernate Oracle Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Abhay,

Could you please share some link explaining the purpose and benefits of shadowing concept.

Regards
Salil Verma
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic