Results 21 to 25 of 25
- 08-11-2011, 11:00 PM #21
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 3
Protected constructors have the package private accessibility, i.e. only accessible from within the same package.
However, because the superclass's constructor must run before the subclass's constructor, the subclass can specify
which constructor the use, but only with proper accessibility as well as protected constructors.
This means the a protected constructor cannot be used from another package, but a subconstructor can specify to "use"
a protected superconstructor, for constructing the object it self, but not another object.
Java Code:package thispackage; import anotherpackage.Superclass; class Subclass extends Superclass { //superclass have protected Superclass(); public Subclass() { super(); //Allowed Superclass somethingelse = new Superclass(); //Not allowed }}Ex animo! Hibernate
Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.
- 08-11-2011, 11:16 PM #22
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 3
It may also be good to add:
Constructors are not static; you can not use access protected constructors (in another packages) from non-static methods or initialisers, either.
Initialisers being to headless members:
Java Code:class Class { { System.out.println("Hello from " + this.toString() + "'s initialiser."); } }Ex animo! Hibernate
Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.
- 08-12-2011, 11:25 AM #23
Senior Member
- Join Date
- Mar 2009
- Posts
- 126
- Rep Power
- 0
Excellent bro , thanks a lot for the above information . i clearly understood :)
i could not understand the above line bro :( . yes ,constructors are not static , i know that , but i could not understand the below lineConstructors are not static; you can not use access protected constructors (in another packages) from non-static methods or initialisers, either.
you can not use access protected constructors (in another packages) from non-static methods or initialisers, either.
Last edited by funkygarzon; 08-12-2011 at 11:48 AM.
- 08-12-2011, 02:42 PM #24
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 3
Just emphasising that protected constructor cannot be accessed at all from another package, exception from when specifying show constructor the superclass should use.
Ex animo! Hibernate
Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.
- 08-12-2011, 06:12 PM #25
Senior Member
- Join Date
- Mar 2009
- Posts
- 126
- Rep Power
- 0
thank s for the explanation bro , i can some how get your point by matching the my program that you have corrected . If you can please give me some links containing good java programs for practicing these king of stuffs and all the concepts in java . thanks in advance you bro :)
Similar Threads
-
Error "org.apache.commons.logging package does not exist" appeared
By vjoshi in forum Java ServletReplies: 2Last Post: 06-16-2011, 04:44 PM -
An "if" statement inside a "for" loop?
By soccermiles in forum New To JavaReplies: 18Last Post: 04-20-2010, 03:44 AM -
"package javax.microedition.lcdui doesnt exsist" But on suns webbpage they say it do!
By Addez in forum New To JavaReplies: 4Last Post: 10-30-2009, 07:54 PM -
Eclipse "import not resolved" package problem?
By spamsickle in forum New To JavaReplies: 3Last Post: 08-24-2009, 11:44 AM -
the dollar sign "$", prints like any other normal char in java like "a" or "*" ?
By lse123 in forum New To JavaReplies: 1Last Post: 10-20-2008, 07:35 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks