Thanks<br />Karthik<br />SCJP 1.4, CCNA.<br /> <br />"Success is relative. More the success, more the relatives."
Originally posted by Karthik Veeramani:
Can any 1 please explain the behavior of private and protected constructors? I mean, when they'll cause runtime errors (they dont give compile errors, right?).
Rich Raposa<br /><a href="http://www.javalicense.com" target="_blank" rel="nofollow">http://www.javalicense.com</a><br />Buy Java courseware -> get a free XBox!
Originally posted by Rich Raposa:
If a constructor is protected, then it is only accessible from other classes within the same package, or child classes...
Originally posted by Corey McGlone:
NO!Protected constructors are accessible ONLY from other classes within the package. Child classes outside that package CAN NOT access a protected constructor of the parent class.
Originally posted by Jessica Sant:
why's that -- isn't the def'n of package that it can only be accessed by other classes in the same package. and the def'n of protected is that it can be acced by other classes in the same package, and by subclasses (even if they're outside the package)??
The members of a class type (�8.2) are classes (�8.5, �9.5), interfaces (�8.5, �9.5), fields (�8.3, �9.3, �10.7), and methods (�8.4, �9.4). Members are either declared in the type, or inherited because they are accessible members of a superclass or superinterface which are neither private nor hidden nor overridden (�8.4.6).
...
Constructors (�8.8) are not members.
SCJP 1.4, SCWCD 1.3, SCBCD 1.3
If the access is by a superclass constructor invocation super(. . .) ... then the access is permitted.
...
Otherwise, if the access is by a simple class instance creation expression of the form new C(. . .) ... then the access is not permitted.
Originally posted by Corey McGlone:
NO!Protected constructors are accessible ONLY from other classes within the package. Child classes outside that package CAN NOT access a protected constructor of the parent class.
Rich Raposa<br /><a href="http://www.javalicense.com" target="_blank" rel="nofollow">http://www.javalicense.com</a><br />Buy Java courseware -> get a free XBox!
Don't get me started about those stupid light bulbs. |