Chapter7ObjectsandClasses1.SeethesectionDefiningClassesforObjects.2.Definetheinitializer,createdatafields,anddefinemethods.3.Useaconstructor4.Thenameoftheinitializeris__init__.5.Theselfreferstotheobjectitself.Throughself,themembersoftheobjectcanbeaccessed.6.ThesyntaxforconstructinganobjectisClassName(arguments)Theargumentsoftheconstructormatchtheparametersinthe__init__methodwithoutself.Theconstructorfirstcreatesanobjectinthememoryandtheninvokestheinitializer.7.Initializerisaspecialmethodthatiscalledwhencreatinganobject.8.Theobjectmemberaccessoperatoristhedot(.).9.YouneedtopassanargumentintheconstructorA()toinvoketheclassA’sinitializer.10.(a)Theconstructorshouldbedefinedas__init__(self).(b)radius=3shouldbeself.radius=311.countis100timesis012.countis0nis113.__iisaprivatedatafieldandcannotbeaccessedfromoutsideoftheclass.14.Correct.TheprintoutisWelcome.15.__onisaprivatedatafieldandcannotbeaccessedoutsidetheclass.ThewaytofixitistoaddagettermethodfortheBooleanpropertyasfollows:classA:def__init__(self,on):self.__on=notondefisOn(self):returnself.__ondefmain():a=A(False)print(a.isOn())main()#Callthemainfunction16.Twobenefits:(1)forprotectingdataand(2)foreasytomaintaintheclass.InPython,privatedatafieldsaredefinedwithtwoleadingunderscores.17.Addtwounderscoresastheprefixforthemethodname.18.Seethetext