static Inner class
posted 24 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
hi,
I want to know where the static inner class is used.also give information about"protected constructor"
thanks in advance
I want to know where the static inner class is used.also give information about"protected constructor"
thanks in advance
posted 24 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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?
Read a discussion here if you like:
Q. What is the differences between static or non-static inner classes?
posted 24 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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!
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!
posted 24 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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
http://www.javaworld.com/javaworld/javatips/jw-javatip106.html
Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
Roseanne Zhang
Ranch Hand
Posts: 1953
posted 24 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
It was SUN itself created this mess and confusion, we will have this kind of legacy errors somewhere for a long time. 

| Do not threaten THIS beaver! Not even with this tiny ad: Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |










