aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes can someone explain me this? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "can someone explain me this?" Watch "can someone explain me this?" New topic
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: 1000
    
    1

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 Java Web Service Developer (1z0-897), 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: 253

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: 253

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
 
subject: can someone explain me this?
 
Similar Threads
constructor
default constructor must inside the Parent class. why?
Child extends Parent, Belongs to same package, Cannot access public variable
explain the concept of data hiding
this() and super()