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 inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "inheritance" Watch "inheritance" New topic


amrit singh
Ranch Hand

Joined: Nov 03, 2000
Posts: 42
JLS says
"constructors and static initializers are not memebers and are
not inherited by the subclasses"
but i am confused
if we declare a static protected class variable
it is inherited by all sublcasses
class P{
static protected int i;
i will be inherited by all sublasses of P.
do i am missing something
Ajith Kallambella

Joined: Mar 17, 2000
Posts: 5782
The code you have given illustrates a static variable declaration and not a static initializer. Static/instance initializers are blocks of code that appears in the class context without any name.
Here is an example I pulled out from my code repository. Since the code is self documentary I will not deliberate much about what is what. This little program also demonstrates the order of invocation of initializers and constructors. Give it a swirl!


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
I agree. Here's the link:
subject: inheritance
jQuery in Action, 3rd edition