File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes confusion in static Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "confusion in static" Watch "confusion in static" New topic

confusion in static

saipavan vallabhaneni
Ranch Hand

Joined: Nov 14, 2008
Posts: 34
its given that static members cannot be inherited but the static methods can be redefined in the sub class.
for the above program the output is :1
in the above program the getVal() is not redefined in the Flidder class ... then how come the f.getVal() is getting executed

and i have doubt with the static variable too

the output is:9
how are we able to access the y in sub class when its not inherited(Minor() { super(y); y = y + 3; })

M Srilatha
Ranch Hand

Joined: Aug 27, 2008
Posts: 137

Static members are inherited by subclasses. Only thing is static methods cant be overridden but they can be redefined. (I guess redefining is like overridding only just the wording is different. THis is my assumption.)

Refer to JLS for more information.

Hope this helps!

Thanks,<br />Srilatha M
Kumara Swamy
Ranch Hand

Joined: Nov 17, 2008
Posts: 34

Static members are inheritable.
so you can access the static methods and static variables of the Super class until and unless they are private.

Kumara Swamy.
saipavan vallabhaneni
Ranch Hand

Joined: Nov 14, 2008
Posts: 34
thanks srilatha and swamy for the information
Sachin Adat
Ranch Hand

Joined: Sep 03, 2007
Posts: 213
static methods are inheritable???
had always thought static means no inheritance......class related

How To Ask Questions On Java Ranch - How To Answer Questions On Java Ranch
geeta vemula
Ranch Hand

Joined: Jul 18, 2008
Posts: 208
Static methods are inherited but they cannot be overridden.

Geeta Vemula
Rajshekhar Paul
Ranch Hand

Joined: Oct 17, 2006
Posts: 140
Based on the access level of the superclass members both static & instance, all of them are inherited to the subclasses. But only, instance methods can be overridden if they are not final.

When it's obvious that you have to do it, just do it without shattering your thoughts over different directions.
Ankit Garg

Joined: Aug 03, 2008
Posts: 9466

just to add, you cannot hide a final static method from a super class...

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Bert Bates

Joined: Oct 14, 2002
Posts: 8898
And remember everyone - please cite the author of whatever mock exam questions you discuss!

Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
I agree. Here's the link:
subject: confusion in static
It's not a secret anymore!