This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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
Similar Threads
Doubts on Protected Members
Protected members inheritance
Old Chestnut: Protected Access
Visibility limits of protected access Specifier