Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

inheritance

 
amrit singh
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!!!
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.e
i will be inherited by all sublasses of P.
do i am missing something
thanxxxxx
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!

Ajith
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic