File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes static Inner class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "static Inner class" Watch "static Inner class" New topic

static Inner class

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I want to know where the static inner class is used.also give information about"protected constructor"
thanks in advance
Roseanne Zhang
Ranch Hand

Joined: Nov 14, 2000
Posts: 1953
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

Joined: Sep 29, 2000
Posts: 75
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

Joined: Jan 30, 2000
Posts: 3226
I agree with Roseanne. But even so, some decent Java publications keep using the term "Static inner classes":

Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
Roseanne Zhang
Ranch Hand

Joined: Nov 14, 2000
Posts: 1953
It was SUN itself created this mess and confusion, we will have this kind of legacy errors somewhere for a long time.
I agree. Here's the link:
subject: static Inner class
It's not a secret anymore!