Forums Register Login

Default Constructor

+Pie Number of slices to send: Send
Can a default constructor of any class has package access or not? can any one give me brief idea about it..
+Pie Number of slices to send: Send
Default constructors have two access levels, public and default. Public classes get public access level for their default constructors.
+Pie Number of slices to send: Send
hi

Default Constructor which is implicitly inserted by the compiler if there's no constructor, then it takes the access level of the class.

if the access level of the class is public then the access level of the default constructor will be also public, if the access level of the class is default then the access level of the constructor will be also default... and will continue in that fashion for all other access levels...

NOTE: constructors can be of any access level, even the default constructor which the compiler puts in can be of any access level because if the class is not a top level class then it could have any access level. Only top level classes can have only either public or default
+Pie Number of slices to send: Send
 

Only top level classes can have only either public or default



One "only" too many. Should be "Top level classes can have only either public or default".
+Pie Number of slices to send: Send
agreed with the correction
LOOK! OVER THERE! (yoink) your tiny ad is now my tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1028 times.
Similar Threads
Inheritance Issue
Default constructor..
Default Constructor in Sub/Super Class
"JavaRanch Rule Round-up Game" error?
Again java cap 38
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 03:31:45.