• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static Inner class

 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
hi,
I want to know where the static inner class is used.also give information about"protected constructor"
thanks in advance
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no such thing called static inner class according to JLS:
Read a discussion here if you like:
Q. What is the differences between static or non-static inner classes?
 
Asuthosh Borikar
Ranch Hand
Posts: 75
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are using abstract classes, protected constructors come very handy.
Obviously, the abstract class can not be instantiated. Why have a constructor? For the following reason:
The abstract class will be extended by concrete subclasses. If you have more than one such concrete subclass, they all share the members of the abstract super class. How do you initialize these super class member variables? Or better yet, let's assume that you have to get a resource each time you instantiate any of these subclasses. Rather than have the code to get the resource in all the constructors of these subclasses, it's better to have a protected constructor in the superclass, then call the super class constructor from the subclass.
To summarize, if you have an abstract class, and if all the subclasses of this abstract class have some common functionality at the time of creating a new instance, that functionality can be included in a protected constructor in the abstract super class and this constructor could be called by the constructors in the subclasses.
Hope this Helps!
 
Tony Alicea
Desperado
Sheriff
Posts: 3226
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Roseanne. But even so, some decent Java publications keep using the term "Static inner classes":
http://www.javaworld.com/javaworld/javatips/jw-javatip106.html
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It was SUN itself created this mess and confusion, we will have this kind of legacy errors somewhere for a long time.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic