Staticimportisnotusedforstaticnestedclasses.Theyareimportedwithnormalimports.
Eachtoplevelclassresidesinasourcefileofitsown.
Theorderyouchooseforthemembersandinitializersofyourclasscanhaveagreateffectonlearnability.However,there'snosinglecorrectrecipeforhow
todoit;differentclassesmayordertheircontentsindifferentways.
Whatisimportantisthateachclassusessomelogicalorder,whichitsmaintainercouldexplainifasked.Forexample,newmethodsarenotjusthabitually
addedtotheendoftheclass,asthatwouldyield"chronologicalbydateadded"ordering,whichisnotalogicalordering.
3.4.2.1Overloads:neversplit
Whenaclasshasmultipleconstructors,ormultiplemethodswiththesamename,theseappearsequentially,withnoothercodeinbetween(noteven
privatemembers).
TerminologyNote:blocklikeconstructreferstothebodyofaclass,methodorconstructor.Notethat,bySection4.8.3.1onarrayinitializers,anyarray
initializermayoptionallybetreatedasifitwereablocklikeconstruct.
Bracesareusedwith if , else , for , do and while statements,evenwhenthebodyisemptyorcontainsonlyasinglestatement.
BracesfollowtheKernighanandRitchiestyle("Egyptianbrackets")fornonemptyblocksandblocklikeconstructs:
3.4Classdeclaration
3.4.1Exactlyonetoplevelclassdeclaration
3.4.2Orderingofclasscontents
4Formatting
4.1Braces
4.1.1Bracesareusedwhereoptional
4.1.2Nonemptyblocks:K&Rstyle