Attention! Your ePaper is waiting for publication!
By publishing your document, the content will be optimally indexed by Google via AI and sorted into the right category for over 500 million ePaper readers on YUMPU.
This will ensure high visibility and many readers!
Возьмит<strong>е</strong> фрагм<strong>е</strong>нты кода из басс<strong>е</strong>йна и пом<strong>е</strong>стит<strong>е</strong> их на пусты<strong>е</strong> строки. Каждый<br />
фрагм<strong>е</strong>нт можно использовать н<strong>е</strong>сколько раз. В басс<strong>е</strong>йн<strong>е</strong> <strong>е</strong>сть и лишни<strong>е</strong><br />
фрагм<strong>е</strong>нты. Вам нужно создать набор классов, которы<strong>е</strong> будут компилироваться<br />
и работать как <strong>е</strong>диная программа. Н<strong>е</strong> обольщайт<strong>е</strong>сь, задача сложн<strong>е</strong>й, ч<strong>е</strong>м<br />
каж<strong>е</strong>тся на п<strong>е</strong>рвый взгляд!.<br />
c l a s s R ow boat ........................................ {<br />
насл<strong>е</strong>довани<strong>е</strong> Возьмит<strong>е</strong> фрагм<strong>е</strong>нты кода из басс<strong>е</strong>йна и пом<strong>е</strong>стит<strong>е</strong> их на пусты<strong>е</strong> строки. Каждый фрагм<strong>е</strong>нт можно использовать н<strong>е</strong>сколько раз. В басс<strong>е</strong>йн<strong>е</strong> <strong>е</strong>сть и лишни<strong>е</strong> фрагм<strong>е</strong>нты. Вам нужно создать набор классов, которы<strong>е</strong> будут компилироваться и работать как <strong>е</strong>диная программа. Н<strong>е</strong> обольщайт<strong>е</strong>сь, задача сложн<strong>е</strong>й, ч<strong>е</strong>м каж<strong>е</strong>тся на п<strong>е</strong>рвый взгляд!. c l a s s R ow boat ........................................ { public ........... rowTheBoatO { r e t u r n " s t r o k e n a t a s h a " ; } class ........... { private int ........... void ........ length = len; } public int getLengthO { } public move() { return .) { class TestBoats { ........................ Main () { X } .............. Подсказка: ........ Ы - new BoatO ; ЭИЛО М О Ч ~ Sailboat b2 - new () ; входа Rowboat ....... =-M6WK0WBcat() ; програм му. b2.setLength(32) ; xyz = bl. ....... () ; xyz += b3. ....... 0 ; xyz += ...... .moveO; System.Windows .Forms .MessageBox.Show (xyz); } class ............... : Boat { } public ..................... 0 { ) return " ................ " ; дальш<strong>е</strong> > 257
н<strong>е</strong>много практики А ажн<strong>е</strong>ш<strong>е</strong> )^<strong>е</strong>ш<strong>е</strong>ни<strong>е</strong> c la s s А { p u b lic с ъ л <strong>е</strong> с ь „ с О О <strong>е</strong> г г ^ <strong>е</strong> Н и й а = 6 Ь = 5 а = 5 56 11 65 c la s s В : А { virtual s t r in g ml О { p u b lic override s t r in g ml 0 { p u b lic virtual s t r in g m3() { c la s s С : В { } p u b lic override s t r in g m3() { Вы вс<strong>е</strong>гда мож<strong>е</strong>т<strong>е</strong> использовать конкр<strong>е</strong>тно<strong>е</strong> вм<strong>е</strong>сто q += b . m l ( ) ; общ<strong>е</strong>го, при наличии строчки кода, в которой тр<strong>е</strong>- q += c.m 2 () ; бу<strong>е</strong>тся класс C a n in e , можно создать ссылку на класс q += а .т З О ; A 's m l. A 's m2, C 's m 3, 6 Dog. Поэтому строчка: ------------- А а2 = new С О ; q += c .m l ( ) B 's m l. A 's m2. A 's m3. q += с . m2 О означа<strong>е</strong>т, что вы созда<strong>е</strong>т<strong>е</strong> экз<strong>е</strong>мпляр С и ссылку из q += с .т З () A 's m l. B ' s m2. C 's m3, 6 класса А с им<strong>е</strong>н<strong>е</strong>м а 2 указывающую на н<strong>е</strong>го. Впроч<strong>е</strong>м, им<strong>е</strong>на А, а 2 и С н<strong>е</strong> оч<strong>е</strong>нь наглядны, поэтому при B 's m l. A 's m2. C 's m3. 13 q += a .m lO в<strong>е</strong>д<strong>е</strong>м н<strong>е</strong>сколько прим<strong>е</strong>ров со значимыми им<strong>е</strong>нами: B ' s m l. C 's m2, A 's m3. q += b.m2 0 San dw ich m ySandwich = new B L T (); q += c.m3 0 A 'S m l. B ' s m2, A 's m3. C h eese in g r e d ie n t = new A gedV erm ontC heddar( ); S o n g b ir d t w e e t y = new N o r th e r n M o c k in g b ir d ( ); q += a2 .m l( ) ; q += a 2 .m 2 ( ) ; q += a 2 .m 3{); B 's m l. A 's m2, C 's m3. 6 A 'S m l. A 's m2, C 's m3. 13 258 eiHeHue j=*e^ca Б басс<strong>е</strong>йн<strong>е</strong> class Rowboat^ 8oat { public string rowTheBoatO { return "stroke natasha"; ) ) class Boat { { private int length ; public void setLength ( in t len > } length = len; public int getLengthO { return length ) public virtual string move{) { return " d rift ) class TestBoats { } public static void Main(){ } xyz = Boat bl = new Boat(); Sailboat b2 = new . .SAlXfeftat... () ; Rowboat ...l?3......= new Rowboat (); b2. setLength(32); xyz = bl. M0Ve_ 0 ; xyz += b3. .mp.V'2.. 0; xyz += b2 _.move () ; System.Windows. Forms.MessageBox.Show(xyz) , class ..SAlib.Oat...'- Boat { ) public .override string 0 { } return " hoist sail ";