You are on page 1of 36

Questions to .

NET and Programming in C# Part 2: 101->235

101.

interface int : one! t"o!t#ree$ % &#ic# of t#e fo''o"ing statements are true for t#e a(o)e code* a- one !t"o !t#ree must (e c- one! t"o! t#ree can (e c'asses. c'asses or interfaces. ((o)e code "i'' generate an d) one, two, three must be error as mu'ti.'e )a'ues after interfaces. t#e : is not a''o"ed in C#. /f Parent is a (ase c'ass and C#i'd is its deri)ed c'ass t#en "#ic# of t#e fo''o"ing statements is not )a'id* a- Parent .10ne" C#i'd1-2 c- Parent .10ne" Parent1-2 (- C#i'd c10ne" C#i'd1-2 d) Child c1=new Parent(); n3 c'ass t#at contain one or more a(stract met#ods must (e dec'ared as 4444 a- /nterface c- 5tatic b) Abstract d- Pri)ate Which of the followin are correct statements for im!lementin an abstract class. a- .u('ic a(stract )oid c'ass c- a(stract .u('ic C'ass C'ass b) !ublic abstract class ClassA &#ic# of t#e fo''o"ing met#ods can (e ca''ed as an 6o.eration7* 889C'ass .met#od 1-9 : )irtua' or a(stract mem(ers cannot (e .ri)ate a- .u('ic )oid met#od 1-$% c- )oid met#od 1-2

+0.5,

102.

+1.0,

103.

+1.0,

104.

+1.0,

105.

+1.0,

10:. 10;. 10=.

10?. 110.

(- .u('ic )oid met#od $% d) !ublic "oid methodA(); (stract met#ods #o'ds on'3: +1.0, a) return t#!e c) name of method (- return statements d) Parameters 44 can (e t#oug#t as a mou'd of a c'ass. +1.0, a) abstract class c- /nterface (- <e'egates d- static c'ass &#ic# of t#e fo''o"ing is a )a'id statement to im.'ement c'ass > in t#e +1.0, c'ass . a- c'ass im.'ements > c) class A$% (- c'ass im.'ements c'ass > d- c'ass >: Pro.erties .ro)ide t#e o..ortunit3 to .rotect a fie'd in a c'ass (3 +1.0, reading and "riting to it using accessors. a) &rue (- @a'se 1. using 53stem2 +1.5, 2. .u('ic c'ass Parent$ 3. .u('ic )irtua' )oid Count1-$ A. Conso'e.&riteBine1C100C-2 5. % :. %2 ;. .u('ic c'ass C#i'd:Parent =. $ ?. .u('ic o)erride )oid Count1-$ 10. Conso'e.&riteBine1C1000C-2 11. % 12. .u('ic static )oid Dain1-$ 13. Parent .0ne" C#i'd1-2 1A. ..Count1-2 15. % % &#at "i'' (e t#e out.ut of t#e a(o)e .rogram*

11A. &#at error does t#e fo''o"ing code generates "#en com.i'ed* 1. a(stract c'ass C'ass 2. $ 3. .u('ic )oid getNum(er1-2 A. % 5. c'ass C'ass :C'ass :. $ % a- T#e name of (ase c'ass used c- T#e c'ass C'ass must is in)a'id dec'are as a(stract as t#e c'ass does not im.'ements a'' t#e met#ods of a(stract (ase c'ass. (- 'Class. et(umber()' must declare a bod# because it is not mar)ed abstract. 115.

+1.5,

11:.

a(stract c'ass C'ass +1.5, $ .ri)ate a(stract )oid getNum(er1-2 % c'ass C'ass :C'ass $% &#at error does t#e fo''o"ing code generates "#en com.i'ed* a- T#e name of (ase c- T#e c'ass C'ass must c'ass used is in)a'id. dec'are as a(stract as t#e c'ass does not im.'ements a'' t#e met#ods of a(stract (ase c'ass. (- 9C'ass.getNum(er1-9 d) &he abstract member cannot must dec'are a (od3 be !ri"ate. (ecause it is marEed a(stract. &#ic# of t#e fo''o"ing statements are true* +1.5, a) A class inherits all c- &#en an interface met#od is interface ma..ed onto a )irtua' met#od im!lementations in a c'ass! it is .ossi('e for !ro"ided b# its base deri)ed c'asses to o)erride t#e classes. )irtua' met#od b) Without e*!licitl# re- dn eF.'icit interface mem(er im.'ementing! a im.'ementations can (e deri"ed class can a(stract. alter the interface ma!!in s it inherits from its base classes

11;.

using 53stem2 .u('ic c'ass Parent $ .u('ic )irtua' )oid <is.'a31-$ Conso'e.&riteBine1C100C-2 % % .u('ic c'ass C#i'd1:Parent $ .u('ic o)erride )oid <is.'a31-$ Conso'e.&riteBine1C1000C-2 %% .u('ic c'ass C#i'd2:Parent $ .u('ic o)erride )oid <is.'a31-$ Conso'e.&riteBine1C1000C-2 % .u('ic static )oid Dain1- $ C#i'd1 c10ne" C#i'd11-2 C#i'd2 c20ne" C#i'd21-2 Parent .0c22 c1.<is.'a31-2 ..<is.'a31-2 %% &#at "i'' (e t#e out.ut of a(o)e code "#en com.i'e8run* a- T#e code "i'' generate c) &he out!ut of the code will an error! as t#e o(Gect be$ . is not .ro.er'3 1000 instantiated. 1000 (- T#e code "i'' generate d- T#e out.ut of t#e code "i'' (e: an error! as t#e o(Gect 1000 c2 is not .ro.er'3 100 instantiated 88c#HIng trJn# dH dKu ngoLc - EiMm tra (Nng mOt: (P ta3 using 53stem2 .u('ic c'ass Parent $ .u('ic )irtua' )oid <is.'a31-$ Conso'e.&riteBine1C100C-2 % % .u('ic c'ass C#i'd1:Parent $ .u('ic o)erride )oid <is.'a31-$ Conso'e.&riteBine1C1000C-2 % .u('ic )oid <is.'a31int i-$ Conso'e.&riteBine1C$0%C!i-2 %% .u('ic static )oid Dain1- $ Parent . 0ne" C#i'd11-2 ..<is.'a31-2

+2.0,

11=.

+2.0,

..<is.'a31?0-2 %% &#at "i'' (e t#e out.ut of a(o)e code "#en com.i'e8run* a- T#e code "i'' generate c) &he code will enerate a an error! as t#e o(Gect com!ilation error, as !arent . is not .ro.er'3 class does not ha"e a instantiated. dis!la# method with one ar ument. (- T#e out.ut of t#e code d- T#e out.ut of t#e code "i'' (e: "i'' (e: 1000 1000 ?0 1000 &#ic# of t#e fo''o"ing statements are true "it# res.ect to a +2.0, )irtua' met#od a- /n a )irtua' met#od c) %ecause methods are in)ocation! t#e allowed to hide inherited com.i'e-time t3.e of methods, it is !ossible for a t#e instance for "#ic# class to contain onl# one t#e in)ocation taEes "irtual method with the .'ace determines t#e same si nature. actua' met#od im.'ementation to in)oEe. (- +or e"er# "irtual method inherited b# or declared in a class, there e*ists a most deri"ed m!lementation of the method with res!ect to that class. &#at "i'' (e t#e out.ut of t#e code (e'o"* +2.0, c'ass Qoom$ .u('ic (oo' isEm.t31-$ return 1true-2 % % c'ass 5taffQoom: Qoom$ .u('ic new (oo' isEm.t31-$ return fa'se2 % .u('ic static )oid Dain1- $ Qoom Q1 0 ne" 5taffQoom1-2 53stem.Conso'e.&riteBine1Q1.isEm.t31--2 %

11?.

120.

% a) &rue c- @a'se (- T#e code "i'' not d- T#e code "i'' not com.i'e and com.i'e and generate generate an error at 'ine ?. an error at 'ine :. a(stract c'ass C'ass$ +2.0, .u('ic a(stract )oid getNum(er1-2 .u('ic a(stract )oid getReig#t1-2 .u('ic (oo' isEm.t31-$return 1true-2% % a(stract c'ass C'ass :C'ass$ .u('ic a(stract )oid get&idt#1-2 % c'ass C'ass>:C'ass $ % &#at c#anges s#ou'd (e done in t#e a(o)e code so t#at t#e code does not generate an3 error at com.i'e time* a- Qemo)e t#e a(stract cdd t#e a(stract modifier for modifier for t#e t#e function C'ass.isEm.t31C'ass.getNum(er1-! C'ass.getReig#t1met#ods (- Qemo)e t#e a(stract d) ,m!lement the methods modifier for t#e c'ass et(umber(), et-ei ht(), C'ass etWidth() in the class Class%. cdd t#e a(stract modifier for t#e c'ass C'ass> &#ic# of t#e fo''o"ing statements are true "it# res.ect to +2.0, a(stract functions* a) Abstract e"ent cn o)erriding e)ent declarations are onl# dec'aration can inc'ude a ne" !ermitted in abstract modifier. classes. b) An o"erridin e"ent dn a(stract e)ent dec'aration declaration must s.ecifies t#at t#e accessors of s!ecif# the e*act t#e e)ent are )irtua'! (ut does same accessibilit# not .ro)ide an actua' modifiers, t#!e, and im.'ementation of t#e name as the accessors. inherited e"ent cn o)erriding e)ent dec'aration s#ou'd not inc'ude t#e sealed

121.

122.

123.

12A.

125.

modifier. c'ass Qoom$ +2.5, int num(er002 .u('ic (oo' isEm.t31-$ return 1num(er>0-2 % % c'ass 5taffQoom: Qoom$ int num(er0102 .u('ic ne" (oo' isEm.t31-$ return 1num(er>0-2 % .u('ic static )oid Dain1- $ Qoom Q10ne" 5taffQoom1-2 53stem.Conso'e.&riteBine1Q1.isEm.t31--2 5taffQoom Q20ne" 5taffQoom1-2 53stem.Conso'e.&riteBine1Q2.isEm.t31--2 % % T#e out.ut of a(o)e code "i'' (e: a- 0!10 d) +alse, &rue (- 10!0 e- T#e code "i'' generate an error. c- True! @a'se &#ic# of t#e fo''o"ing statements are correct* +2.5, a- BiEe a non-a(stract c) An e*!licit interface member c'ass! an a(stract im!lementations can be c'ass must .ro)ide abstract. im.'ementations of a'' mem(ers of t#e interfaces t#at are 'isted in t#e (ase c'ass 'ist. (n a(stract c'ass is d) An e*!licit interface member not .ermitted to ma. im!lementations are interface onto a(stract !ermitted to call abstract met#ods methods. interface /Det#ods +2.5, $ )oid @1-2 )oid S1-2 % a(stract c'ass C: /Det#ods $ )oid /Det#ods.@1- $ @@1-2 %

)oid /Det#ods.S1- $ SS1-2 % .rotected a(stract )oid @@1-2 .rotected a(stract )oid SS1-2 % Consider t#e a(o)e code. T#e non-a(stract t#at deri)e from C "i'' #a)e to im.'ement: a- @1c) ..() b) ++() d- S112:. Tsing directi)es are .ro)ided to faci'itate t#e use of names.aces. a) &rue (- @a'se 12;. Names.aces are defined using 44444 statements. a) /sin c- 53stem (- C'ass d- Names.ace 12=. &#ic# of t#e fo''o"ing statements correct'3 dec'ares a names.ace* a- Names.ace$ ----- ----% c- names!ace (ames!acename0 11111 11112 (- Names.acename$ ---- d- .u('ic names.ace - ----% Names.acename$ ----- ----% 12?. T#e 6using7 a'ias directi)es can (e used to .u'' out and (ring into sco.e one com.onent from a names.ace. a) &rue (- @a'se 130. T#e 4444444 names.ace .ro)ides t#e c'asses and met#ods for mani.u'ating arra3s. a- 53stem./U c) 3#stem.Arra# (- 53stem. rr drra3 131. @or mu'ti.'e 'e)e's of organiVations 444 can (e used. a- C'asses c- a names.ace (- 53stem names.ace d) a nested names!aces 132. T#e 44444444names.ace contains a'' code reWuired to interact "it# t#e inc'uding t#e conso'e out.ut. a- /U c- C'ass b) 3#stem d- Names.ace 133. &#en a c'ass is used inside its names.ace! t#e 4444444 of t#at c'ass is used. a- Qua'ified name c) /n4ualified name (- Names.ace name 13A. 44444 Ee3"ord is used to im.ort t#e c'asses of t#e names.ace a) usin c- names.ace (- c'ass d- im.ort 135. T#e 53ntaF of a .redefined 5ort met#od is: arra3tosort.5ort1c) 3#stem.Arra#.3ort(Arra#tosort) (rra3tosort. rra3.5ort1- d- 53stem. rra3.5ort1-

+0.5, +0.5, +0.5,

+0.5, +0.5,

+1.0, +1.0,

+1.0,

+1.0, +1.0,

13:.

C'asses in t#e >ase C'ass Bi(rar3 are categoriVed into 444444 (ased on t#eir functiona'it3. assem('ies c..'ication (- <irecti)es d) (ames!aces T#e s3ntaF for dec'aring arra3 is: a- arra3name <ataT3.e+,2 (- arra3name+, <ataT3.e2 names.ace s.ace1$ % names.ace s.ace2$ % &#at does t#e a(o)e code im.'ement: a- Nested names.aces cd)

+1.0,

13;.

+1.0, <ataT3.e arra3name+,2 5ata&#!e67 arra#name; +1.5,

13=.

c-

Rierarc#ica' names.aces +1.5, /nterface All the mentioned o!tions +1.5,

13?.

(- Du'ti 'e)e' names.aces &it#in t#e names.ace "e can dec'are fo''o"ing: a- C'ass d(not#er names.ace e) c- de'egates names.ace 5.ace1$ names.ace 5.ace2$ c'ass D3C'ass$ % %% T#e fu''3 Wua'ified name of c'ass D3C'ass is : a- 5.ace1.D3C'ass1(5.ace2.D3C'ass1-

1A0.

c) d-

3!ace1.3!ace8.9#Cl ass() 5.ace2.5.ace1.D3C'a ss1+1.5,

1A1.

names.ace Co''ege.Bi(rar3$ names.ace 5#e'f$ c'ass >ooE$ % % % T#e fu''3 Wua'ified name of c'ass >ooE is: a- 5#e'f.>ooE1c) dColle e.:ibrar#.3helf. %oo)() Bi(rar3.5#e'f.>ooE1-

1A2.

(- Co''ege.Bi(rar3.>ooE1c'ass Test$ static )oid Dain1- $ int+, rra310 $3!2!1%2 int i0 rra3./ndeFUf1 rra31!3-2 Conso'e.&riteBine1i-2

+1.5,

1A3.

% % &#at "i'' (e t#e out.ut of a(o)e code a- 3 (- 2 c'ass Question$ static )oid Dain1- $ int+, Bist0 $30!20!10%2 rra3./ndeFUf1Bist!30-2 % % &#at "i'' (e t#e out.ut of a(o)e code a- 3

cd)

1 0 +1.5,

1AA.

1A5.

1A:. 1A;.

1A=.

(- 2 T#e 444444444444444 names.ace s3nc#roniVation. a- 53stem c) 3#stem.&hread (- 53stem.T#reading d- 53stem.53nc#roniVe &#en t#e arra3 is initia'iVed at t#e same time t#e3 are created! t#e c# com.i'er determines t#e siVe of arra3 using 44444444 a- t#e defau't arra3 siVe for eac# data t3.e. c) the number of items in the initiali;ation list. (- t#e com.i'ers .resetting for eac# data d) &he number !resent t3.e arra3. in the s4uare brac)et ne*t to the data t#!e at the ri ht hand side. >3 defau't t#e com.i'er o.ens 44444assem('3. a- mscor'i(.d'' c) s#stem.dll (- Cdefau't.d'' d- names.ace.d'' &#ic# of t#e fo''o"ing statements are true* a) An arra# is a data structure that d- T#e e'ement t3.e of an contains a number of "ariables, which arra3 can (e an3 t3.e! are accessed throu h com!uted (ut not an arra3 t3.e indices. b) &he dimension len ths are not !art of e) At run1time, a "alue the t#!e of the arra#, but rather are of an arra# t#!e is established when an instance of the null or a reference to arra# t#!e is created at run1time. an instance of that arra# t#!e. c- T#e e'ements of t#e arra3 are a'' of t#e different t3.es. &#ic# of t#e fo''o"ing statements are true "it# res.ect to an rra3 t3.e. a- 53stem. rra3 is itse'f an arra3-t3.e d) An im!licit reference

T#e code "i'' generate a com.i'e time error. d- 1 contains c'asses usefu' for +1.5,

c-

+1.5,

+2.0, +2.0,

+2.0,

b)

&he 3#stem.Arra# t#!e is the abstract base t#!e of all arra# t#!es

e)

con"ersion e*ists from an# arra# t#!e to 3#stem.Arra# &he members of an arra# are the members inherited from class 3#stem.Arra#. +2.0,

c1A?.

n im.'icit reference con)ersion eFists from 53stem. rra3 to an3 arra3 t3.e using 53stem2 c'ass Test$ static )oid Dain1$ int+, rra310 $3!2!1%2 <is.'a311 rra31-2 rra3.5ort1 rra31-2 <is.'a311 rra31-2 % static )oid <is.'a311 rra3 . rra3$ foreac#1int t in . rra3-$ Conso'e.&rite1t-2 %% % T#e out.ut of code "i'' (e 3 2 1 1 2 3 T#e code "i'' generate a runtime error.

&#at "i'' (e t#e out.ut of a(o)e code* a- T#e code "i'' generate an error at ccom.i'e time since t#e 5ort1- function of rra3 returns an integer num(er.

b) 150.

&he out!ut of the code will be$ <8118<

d-

&#at out.ut does t#e code (e'o" generate "#en com.i'ed8run* 1. c'ass Em.'o3ee$ 2. .u('ic int Em.'o3ee/d2 3. .u('ic static Em.'o3ee getEm./d1int Em./d-$ A. Em.'o3ee em.0ne" Em.'o3ee1-2 5. em..Em.'o3ee/d0Em./d2 :. return1em.-2 ;. %

+2.0,

=. % ?. c'ass Test$ 10. .u('ic static )oid Dain1-$ 11. Em.'o3ee+, em.s0ne" Em.'o3ee+2,2 12. em.s+0,0Em.'o3ee.getEm./d11-2 13. em.s+1,0Em.'o3ee.getEm./d12-2 1A. foreac#1Em.'o3ee e in em.s15. 53stem.Conso'e.&riteBine1e.Em.'o3ee/d-2 1:. % % aT#e code "i'' generate a com.i'e time error at 'ine 12 and 'ine 13. b) &he code will com!ile successfull# d- T#e code "i'' com.i'e and out!uts will be$ successfu''3 and 1 out.ut "i'' (e:0 8 1 &#at "i'' (e t#e out.ut of t#e code (e'o" "#en com.i'ed8run* +2.5, 1. c'ass Test $ 2. .u('ic static )oid Print1o(Gect+, arr-$ 3. foreac#1o(Gect . in arrA. 53stem.Conso'e.&riteBine1.-2 5. % :. .u('ic static )oid Dain1-$ ;. string s0CProgramming in c#C2 =. c#ar+, se.arator0$9 9%2 ?. string+, "ords0s.5.'it1se.arator-2 10. Print1"ords-2 11. % % a- T#e code "i'' generate an error at 'ine 10 c- &he code will com!ile as con)ersion not a''o"ed for one arra3 successfull# and t3.e to anot#er arra3 t3.e. out!ut will be Pro rammin ,n c= (T#e code "i'' generate an error at com.i'e time at 'ine ? as t#e function 5.'it used is not su..orted string data t3.e. 1. c'ass Test$ 2. .u('ic static )oid Dain1-$ 3. int i002 A. c#ar c09s92 5. o(Gect+, o(G rra30ne" o(Gect+3,2 T#e code "i'' generate a nu'' eFce.tion! cas t#e em.'o3ees are not initia'iVed.

151.

152.

+2.5,

153.

15A.

155. 15:.

:. o(G rra3+0,0ne" o(Gect1-2 ;. o(G rra3+0,0i2 =. o(G rra3+0,0c288ne" c#ar1-2 ?. % 10. % T#e a(o)e code is com.i'ed and run. T#e .ossi('e error is: a- T#e code "i'' generate a com.i'e time c) &he code will com!ile error at 'ines ; and = as t#e arra3 can successfull#. #a)e on'3 one t3.e of data. (- T#e code "i'' generate a com.i'e time error at 'ines ; and = as t#e im.'icit con)ersion of int and c#ar to a o(Gect t3.e is not .ossi('e. &#ic# of t#e fo''o"ing statements are true* 88D5<N 'ocE statement an im.'icit (oFing con)ersion can (e c) &he e*!ression of a .erformed for t#e eF.ression of a 'ocE loc) statement must statement. denote a "alue of a reference1t#!e. (- /t is an error for t#e 'ocE eF.ression to d- &he loc) )e#word denote a )a'ue of a )a'ue-t3.e mar)s a statement bloc) as a critical section. using 53stem2 c'ass Test$ .u('ic static )oid Dain1$ int )a'ue 0/nt32.Parse1C???53C-2 dou('e d)a'0<ou('e.Parse1C1.3A33EX35C-2 Conso'e.&riteBine1)a'ue-2 Conso'e.&riteBine1d)a'-2 % 2; &#at "i'' (e t#e out.ut of a(o)e code "#en com.i'ed8run* a) &he code will enerate a com!ile time c- T#e out.ut of a(o)e error. code "i'' (e ???53 1.3A33E35 (- T#e code "i'' generate a com.i'e time d- T#e out.ut of a(o)e error. code "i'' (e ???53 1.3A33EX35 44444444 is a unit of c'ass de.'o3ment. a) An Assembl# cn EFecuta('e fi'e (Danifest T#e eFtension of an assem('3 is 444444444

+2.5,

+2.5,

+0.5, +0.5,

15;. 15=. 15?. 1:0. 1:1.

1:2.

1:3. 1:A.

a- .eFe c- .cs b) .dll d- .dd' n assem('3 cannot (e used in more t#an one a..'ication at a time. a- True b) +alse Ee3 .air is created using t#e 4444444uti'it3. a- Ee3.eFe c- snE.eFe b) sn.e*e d- Ee3.snE Pri)ate assem('ies #a)e no )ersioning .o'ic3. a- True b) +alse T#e 44444 .acEage forms t#e (asic unit of )ersioning. a) An Assembl# cn EFecuta('e fi'e (Danifest T#e s3ntaF to create an assem('3 fi'e is: acsc8out:Yassem('3 name>8target c) csc >out$?assembl# Yfi'ename1 fi'ename2..> name@>tar et$librar # ?filename1 filename8..@ (csc 8out:Yassem('3 name>8'i(rar3 d- csc 8out: 8target: Yfi'ename1 fi'ename2..> Yassem('3 name> 'i(rar3 Yfi'ename1 fi'ename2..> /dentif3 t#e correct s3ntaF for creating an eFecuta('e fi'e. acsc 8out:Y eFecuta('e name c- csc 8out:YeFecuta('e >8'i(rar3:eFe Yfi'ename1 fi'ename2..> name>8target Yfi'ename1 fi'ename2..> b) csc >out$? e*ecutable name d- csc 8out:Y eFecuta('e @>tar et$e*e?filename1 name filename8..@ >8target:'i(rar3Yfi'ena me1 fi'ename2..> @or )ersioning t#e .ri)ate assem('ies! t#e CBQ sim.'3 'oads t#e ne"est assem('ies found in t#e a..'ication director3. a) &rue ( @a'se /dentif3 t#e correct s3ntaF for creating an eFecuta('e fi'e referencing an assem('3. acsc 8out:Y eFecuta('e name c- csc 8out:YeFecuta('e >8r:Yassem('3 name12 name>8target assem('3name2Z2>8'i(rar3:eFe 8r:Yassem('3 Yfi'ename1 fi'ename2..> name12assem('3na me2Z2>Yfi'ename1 fi'ename2..> (csc 8out:Y eFecuta('e name d csc >out$? >8target:eFe 8r:Yassem('3 ) e*ecutable name name1!assem('3name2Z!> @ >tar et$e*e Yfi'ename1 fi'ename2..> >r$?assembl# name1;assembl#na

+0.5, +0.5, +0.5, +1.0, +1.0,

+1.0,

+1.0, +1.0,

1:5.

1::. 1:;.

1:=.

1:?.

1;0.

me8A;@ ?filename1 filename8..@ [ersion num(er of an assem('3 are stored in t#e fo''o"ing format: aY Dinor )ersion >.YDaGor c- YDaGor )ersion>.Y )ersion>.Y>ui'd Num(er>.YQe)ision> Dinor )ersion >.Y>ui'd Num(er>.YQe)ision> (?9aBor "ersion@.? 9inor "ersion d- Y Dinor )ersion @.?Ce"ision@.?%uild (umber@ >.YDaGor )ersion>.YQe)ision>. Y>ui'd Num(er> T#e information a(out a c'ass can (e found out using 44444444 assem('ies c) Ceflection (Danifest d- <e'egates &#ic# of t#e fo''o"ing must (e true for t#e o(Gect t#ro"n (3 a t#ro" statement a) ,t must be assi nable to the c- /t must (e D*ce!tion t#!e. assigna('e to t#e Error t3.e. (/t must (e assigna('e to t#e Error d- /t must (e t3.e. assigna('e to t#e T#ro"a('e t3.e. catc# c'ause ma3 catc# eFce.tion of "#ic# t3.e* aT#e T#ro"a('e T3.e c) &he D*ce!tion &#!e. (T#e Error T3.e. T#e manifest contains data t#at 444 acontains set of t3.es t#at form a c) describes how the 'ogica' unit . elements in assembl# are related to each other. (descri(es t#e resources to form a d describes the other 'ogica' unit of functiona'it3. ) assemblies on which the elements of the assembl# are de!endent. &#ic# of t#e fo''o"ing commands can (e used to create assem('3 named 6m3 ssem('37 from t#e fi'es 6fi'e1.cs and fi'e2.cs7* acsc 8out:m3 ssem('3 8target:'i(rar3 c- csc fi'e1.cs fi'e2.cs 8out:m3 ssem('3.d'' 8target:'i(rar3 fi'e1.cs 8target:'i(rar3 fi'e2.cs b) csc >out$m#Assembl#.dll d- csc >tar et$librar# file1.cs file8.cs 8out:m3 ssem('3.d'' 8target:'i(rar3 fi'e1.cs

+1.0,

+1.0, +1.0,

+1.0,

+1.5,

+1.5,

8out:m3 ssem('3.d'' 8target:'i(rar3 fi'e2.cs 1;1. T#e g'o(a' assem('ies are sa)ed in t#e 444444444 a) in the ?dri"e@$EW,((&EAssembl# c- su( fo'der "it#in t#e folder. fo'der containing t#e ca''ing a..'ication. (.arent fo'der of t#e ca''ing d- same fo'der as t#e a..'ication. ca''ing a..'ication. 1. P'ace t#e assem('3 in t#e g'o(a' assem('3 cac#e. 2. 5ign t#e assem('3 "it# t#e Ee3 .air. 3. Create a Ee3 .air. &#ic# of t#e fo''o"ing is a correct seWuence to con)ert a Pri)ate assem('3 to a 5#ared assem('3. a1!2!3 c) <,8,1 (3!1!2 d- 1!3!2 /f t#ere is a c#ange in t#e maGor num(er or minor num(er of t#e )ersion num(er it indicates t#at 4444444 a) the assembl# is incom!atible with c- assem('3 ma3(e !re"ious "ersions of that com.ati('e "it# assembl#. .re)ious )ersions of t#at assem('3. (a )er3 minor c#ange #as (een made to t#e assem('3. names.ace 5.ace1 $ using 53stem2 .u('ic c'ass $ .u('ic static )oid Dain1- $ o(G 0ne" 1-2 T3.e t1 0 o(G .SetT3.e1-2 Conso'e.&riteBine1CT#e t3.e of o(G is : $0% C! t1-2 % % % &#at "i'' (e t#e out.ut of a(o)e code "#en com.i'ed8run* aT#e code "i'' generate a com.i'e time c- T#e out.ut of code error as c'ass reference is reWuired "i'' (e: for t#e SetT3.e1- met#od. T#e t3.e of o(G is : c'ass. b) &he out!ut of code will be$ d- T#e out.ut of code &he t#!e of obBA is $ 3!ace1.A "i'' (e: T#e t3.e of o(G is : 53stem.5.ace1. &#ic# of t#e fo''o"ing are true a(out t#e fina''3 c'ause of tr3-catc#-fina''3 statements* a/t is on'3 eFecuted after a catc# c) ,t is alwa#s +1.5,

1;2.

+1.5,

1;3.

+1.5,

1;A.

+1.5,

1;5.

+1.5,

c'ause #as eFecuted. (1;:. /t is on'3 eFecuted if a catc# c'ause #as not eFecuted. tr3 $

e*ecuted unless its thread terminates d- /t is on'3 eFecuted if an eFce.tion is t#ro"n. +1.5,

1;;.

1;=.

1;?.

tr3T#is1-2 return2 % catc# 1<i)ide>3\eroEFce.tion F1- $ 53stem.Conso'e.&riteBine1CeFce.tion 1C-2 return2 % catc# 1EFce.tion F2- $ 53stem.Conso'e.&riteBine 1CeFce.tion 2C-2 return2 % fina''3 $ 53stem.Conso'e.&riteBine 1Cfina''3C-2 } &#at "i'' a..ear in t#e standard out.ut if tr3T#is1- t#ro"s a 000000000@ormatEFce.tion* 5e'ect t#e one rig#t ans"er. ac) e*ce!tion 8 eFce.tion 1 fina''3 finall# (eFce.tion 1 d- Not#ing 88 EF.ected catc# or fina''3 +1.5, c'ass $ .u('ic static )oid Dain1-$ tr3$ 53stem.Conso'e.&riteBine1C#e''oC-2 % % % 5e'ect t#e correct statement "it# res.ect to a(o)e code. aT#e code t#at does not t#ro" an3 c- T#e met#od Dain1eFce.tion cannot (e in a tr3 ('ocE. must a'"a3s t#ro" somet#ing if t#e tr3 ('ocE is used "it#out a catc# ('ocE b) We cannot ha"e a tr# bloc) without a catch or>and finall# bloc). &#en "e "ant to associate a Ee3 "it# )a'ues "#ic# of t#e fo''o"ing c'asses +1.5, are .referred* a<ictionar3 88DictionaryBase Class c) -ashtable (Co''ection d- /Enumera('e T#e .rogrammer #as an assem('3 named .ri.d'' "#ic# ot#er .rogrammer +2.0,

1=0.

1=1.

1=2.

a'so "ants used t#e same assem('3. &#ic# of t#e fo''o"ing are t#e correct statements "#en eFecuted "i'' satisf3 t#e a(o)e needs. asn Ee31.snE c) sn F) )e#1.sn) csc 8out:.ri.d'' 8target:'i(rar3 csc fi'e2.cs 8a .Ee3fi'e:Ee3.snE >out$!ri.dll gauti' ]/ .ri.d'' >tar et$librar # file8.cs >a .)e#file$)e#.s n) autil F, !ri.dll (sn ]E Ee31.snE csc 8out:.ri.d'' 8target:'i(rar3 fi'e2.cs 8a .Ee3fi'e:Ee3.snE gauti' .ri.d'' &#ic# of t#e fo''o"ing statements are true* +2.0, a) Assemblies can be shared b# c) Pri"ate assemblies installin it in the lobal are stored in the Assembl# Cache. same folder as that of an a!!lication. (Pri)ate assem('ies s#ou'd not (e dPri)ate assem('ies insta''ed in su(fo'ders (e'o" t#e #a)e .redefined eFecuta('es fo'der. )ersioning .o'ic3. &#ic# of t#e fo''o"ing statements are true "it# res.ect to tr3-catc# ('ocE* +2.0, atr3 statement determines "#ic# catc# c- T#e 'ast catc# t#at is s#ou'd (e used to #and'e an ca.a('e of #and'ing eFce.tion. t#e eFce.tion is eFecuted. b) catch statement are e*amined in order in which the# a!!ear . using 53stem2 +2.0, c'ass Question$ .u('ic static )oid Dain1-$ for 1int i002iY102XXi- $ tr3$ if1i^3000- t#ro" ne" EFce.tion1CE0C-2 tr3$ if1i^3001- t#ro" ne" EFce.tion1CE1C-2 Conso'e.&riteBine1i-2 % catc# 1EFce.tion inner$ iX032 %fina''3 $XXi2%

1=3.

1=A.

1=5. 1=:.

%88tr31 catc# 1EFce.tion outer$ iX032 %fina''3 $XXi2% % % % &#ic# of t#e fo''o"ing 'ines does t#e a(o)e .rogram dis.'a3* aA c: b) G d) H &#ic# of t#e fo''o"ing statements are true a(out t#e Qef'ection P/* a) ,t can be used to effecti"el# find all c) ,t can at times e"en the t#!es in an assembl# and>or be used to emit d#namicall# in"o)e methods in an ,ntermediate assembl#. :an ua e code on the fl# so that the enerated code can be e*ecuted directl#. (/T cannot (e used to mani.u'ate d- T#e Qef'ection P/ ot#er o(Gects on t#e .NET .'atform. uses t#e 53stem.Qef'ection names.ace! "it# t#e Qef'ection c'ass to identif3 t#e t3.e of t#e C'ass (eing ref'ected! &#ic# of t#e fo''o"ing statements (est i''ustrates t#e use of t#e Qef'ection P/. a) Ibtains Class and &#!e c) Ibtains 9ember ,nformation from an Assembl# ,nformation from a Class (Trans'ates a stream of in.ut d) 5#namicall# c#aracters into a stream of in.ut ,n"o)es 9ethods e'ements from Classes in an Assembl# &#ic# of t#e fo''o"ing .ro.erties does t#e T3.e c'ass #a)e* a,sC:ass c) ,sPublic (/sDet#od d) ,sCI9IbBect c'ass Question $ .u('ic static )oid Dain1-$ @unction11-2 %

+2.0,

+2.0,

+2.0, +2.0,

1=;.

1==.

static )oid @unction11-$ tr3$ 53stem.Conso'e.&riteBine1C/n Tr3C-2 return2 % fina''3$ 53stem.Conso'e.&riteBine1C/n @ina''3C-2 % % % &#at "i'' (e t#e out.ut of a(o)e code "#en com.i'e8run* aT#e code "i'' generate a com.i'e time c) &he code will error as t#e met#od @unction11 com!ile cannot (e ca''ed "it#out an o(Gect successfull# and reference. out!ut the followin te*t$ ,n &r# ,n +inall# (T#e code "i'' com.i'e successfu''3 d- T#e code "i'' and out.ut t#e fo''o"ing teFt: com.i'e successfu''3 /n Tr3 and out.ut t#e fo''o"ing teFt: /n @ina''3 /magine t#at 3ou #a)e t"o .cs fi'es. T#e a'.#a.cs fi'e contains a c'ass ca''ed '.#a t#at contains an interna' met#od ca''ed Det#od. T#e (eta.cs fi'e contains a c'ass ca''ed >eta t#at a'so contains an interna' met#od ca''ed Det#od. Can '.#a.Det#od (e ca''ed from >eta.Det#od and )ice )ersa* a/t is de.endent on t#e /nterna' c- /t is .ossi('e if t#e access! "#ic# s.ecifies assem('3s#ara('e eFe fi'e is 'e)e' access. created for t"o fi'es. b) Al!ha.9ethod and %eta.9ethod can call each other onl# if Al!ha and %eta are located in the same assembl#. names.ace Uuter./nner $ c'ass &i(('e $ % % names.ace Test $ using Uuter./nner2 c'ass 5.ecia'&i(('e: /nner.&i(('e $ % % &#ic# of t#e fo''o"ing statements are true a(out t#e a(o)e code*

+2.5,

+2.5,

a-

T#e code "i'' com.i'e successfu''3 as t#e using-names.ace-directi)e cannot (ring t#e names t#at are inside Uuter./nner sco.e.

c- T#e use of /nner.&idget as a (ase c'ass for 5.ecia'&idget is an error (ecause t#e com.i'er cannot reso')e t#e identifier /nner.

b)

1=?.

1?0.

&he code enerates a com!ile time error the code will com!ile successfull# as the usin 1 names!ace1directi"e does not brin the name ,nner itself into sco!e. &#ic# of t#e fo''o"ing statements are true* +2.5, a.NET eFecuta('e .rogram cannot c) Ceflection AP,s direct'3 reference a .NET <BB does not allow modu'e. creatin of assembl# in memor# d#namicall#. (&indo"s 2000 o.erating 53stem is d &he Ceflection AP, ca.a('e of 'oading t"o assem('ies ) allows creatin "it# t#e same name (ut different t#!es on the fl# and )ersion num(ers. in"o)in methods on them. using 53stem2 +2.5, c'ass Test$ .u('ic static )oid Dain1-$ for 1int i002iY102XXi- $ tr3$ tr3$ if1i^3000- t#ro" ne" EFce.tion1CEFce.tion1C-2 Conso'e.&riteBine1i-2 %catc# 1EFce.tion inner$ i_022 if1i^3000- t#ro" ne" EFce.tion1CEFce.tion2C-2 %fina''3 $XXi2% %catc# 1EFce.tion outer$ iX032 %fina''3 $--i2% % %

% &#ic# of t#e fo''o"ing 'ines does t#e a(o)e .rogram dis.'a3* a) 4 c: b) G d= 1. using 53stem2 +2.5, 2. c'ass Test$ 3. .u('ic static )oid Dain1-$ A. tr3$ 5. int .0102 :. Conso'e.&riteBine16enter a num(er7-2 ;. int r0/nt32.Parse1Conso'e.QeadBine1--2 =. .80r2 ?. % 10. catc#1EFce.tion e-$ 11. Conso'e.&riteBine1e-2 12. Conso'e.&riteBine1Conso'e.Error-2 13. % 1A. % 15. % (o)e .rogram is com.i'ed and run. T#e user enters 0 "#en asEed for t#e num(er. <oes t#e code at 'ine 11 and 12 dis.'a3s t#e same out.ut* a/t de.ends u.on t#e com.i'er #o" it c) &he tr# bloc) treats t#e conso'e in.ut. throws an e*ce!tion hence the control oes to catch bloc) but line number 11 and 18 does not !roduce the same out!ut. (T#e tr3 ('ocE t#ro"s an eFce.tion d- T#e tr3 ('ocE do not #ence t#e contro' goes to catc# ('ocE t#ro" an3 eFce.tion (ut 'ine num(er 11 and 12 .roduce #ence t#e contro' t#e same out.ut. does not enter catc# ('ocE #ence 'ines 11 and 12 out.uts not#ing. Ro" can "e create t#e o(Gect d3namica''3 in C#* +2.5, aC# does not a''o" instantiation c- %# usin the of o(Gects at run time. 3#stem.Acti"ator .Create,nstance() method to create an instance of obBect in the followin manner.

1?1.

1?2.

(-

>3 using t#e 53stem.Qef'ection. Create/nstance1- met#od to create an instance of o(Gect in t#e fo''o"ing manner. T3.e m3U(GectT3.e 0 T3.e.SetT3.e@romProg/< 1CD3<''.D3U(GectNameCo(Gect m3U(Gect 0 53stem.Qef'ectrion. Creat/nstance1m3U(GectT3.e-

&#!e m#IbBect&#!e =&#!e..et&#!e+ro mPro ,5 (J9#5ll.9#I(ameJ ) obBect m#IbBect = 3#stem.Acti"ator.C reat,nstance (m#IbBect&#!e) d- /n C#! U(Gect cannot (e instantiated at run time (ut a met#od of a c'ass can (e in)oEed.

1?3.

+2.5,

using 53stem.Qef'ection2 using 53stem2 c'ass Qef'ect $ .u('ic int i0202 .u('ic c#ar c#09a92 .u('ic f'oat f10102 .u('ic )oid Set@'oat1-$ Conso'e.&riteBine1f1-2

% .u('ic )oid Set/nt1-$ Conso'e.&riteBine1i-2 % .u('ic )oid SetC#ar1-$ Conso'e.&riteBine1c#-2 % % c'ass TCPQef'ection $ .u('ic static )oid Dain1$ Qef'ect sender 0 ne" Qef'ect1-2 T3.e t 0 sender.SetT3.e1-2 Dem(er/nfo +, mem(ers 0 t.SetDem(ers1-2 Det#od/nfo +, met#od 0 t.SetDet#ods1-2 @ie'd/nfo +, f10t.Set@ie'ds1-2 Conso'e.&riteBine1CNo of meme(ers:CXmem(ers.Bengt#-2 Conso'e.&riteBine1CNo of fie'ds:CXf1.Bengt#-2 % % &#at "i'' (e t#e out.ut of a(o)e code "#en com.i'ed8run* 88defau't s` cP 5 mem(er: SetRas#Code! EWua's! tostring!getT3.e!Ctor 88fie'd 'a t#uoc tin# 88met#ods: cona 'ai E#ong (ao gom CTUQ aT#e code "i'' generate a com.i'e time c) &he out!ut of error abo"e code will be$ (o of members $ 11 (o of fields$ < (T#e out.ut of a(o)e code "i'' (e: d- T#e out.ut of a(o)e No of mem(ers : 11 code "i'' (e: No of fie'ds: A No of mem(ers : 12 No of fie'ds: 3 1?A. <e'egates #e'. to ca'' a met#od at runtime* a) &rue (- @a'se 1?5. /ndeFers can #a)e user-defined names. a- True. b) +alse 1?:. 5u(scri(ing an o(Gect to an e)ent de.ends on "#et#er t#e e)ent eFists or not. a) &rue (- @a'se 1?;. n instance of a de'egate t3.e enca.su'ates one or more ca''a('e entities. a- True b) +alse 1?=. T#e o(Gect t#at notifies t#e ot#er o(Gects! a(out e)ents is Eno"n as t#e .u('is#er.

+0.5, +0.5, +0.5, +0.5, +0.5,

1??. 200.

201.

202.

203.

20A.

205.

a) &rue (- @a'se T#e t3.e of e)ent dec'aration must (e of 444444444 t3.e. a- <e'egate c) D"ent (- /ndeFers d- Constructor. C'ients can attac# eFecuta('e code for e)ents (3 su..'3ing ____________ a- de'egates ce)ent #and'er (- t#ro" statements d) e"ent subscribers &#ic# of t#e fo''o"ing is a correct statement t#at defines a de'egate* a- .ri)ate )oid D3<e'egate1- 2 d- .u('ic int D3<e'egate1- 2 b) !ri"ate dele ate int 9#5ele ate() ; e- .u('ic de'egate )oid D3<e'egate1a!(- 2 c) !ublic dele ate "oid 9#5ele ate() ; Qeturn t3.e of indeFers is a- same as t3.e of set met#od of a c- (3 defau't set to t#e .ro.ert3. t3.e of indeF used. b) same as return t#!e of et method d- (3 defau't set to an of a !ro!ert#. int data t3.e. &#ic# of t#e fo''o"ing is t#e correct s3ntaF for dec'aring an indeFer. a- !rotected int this6int "ar17 c- .u('ic int t#is1int )ar1(- .u('ic int c'assname+int indeF, d !ublic int this6int ) "ar17 de'egate is a c'ass deri)ed from 444444444 a) 3#stem.5ele ate c- 53stem.C'ass.<e'eg ate (- 53stem.Qef'ection.<e'egate d- <e'egate. C'ass &#ic# of t#e fo''o"ing is t#e correct seWuence to #and'e an e)ent in C# * 1. 5u(scri(e o(Gect 2. Notif3 su(scri(er 3. <efine an e)ent a- 1! 2! 3 c(- 3! 2! 1 d) &#ic# of t#e fo''o"ing is a correct e)ent t#at is named 6 D3<e'egate7 a- .u('ic e)ent D3<e'egate D3E)ent1-2 c(!ublic e"ent 9#5ele ate 9#D"ent; 2! 3! 1 <, 1, 8 (ased on t#e de'egate

+1.0, +1.0,

+1.0,

+1.0,

+1.0,

+1.0,

+1.0,

20:.

+1.0,

.ri)ate e)ent D3<e'egate D3E)ent1-2 d- .u('ic D3<e'egate D3E)ent2 +1.0, Tnsafe code

20;.

C# code can (e c'assified into t3.es: a) 9ana ed code

c-

20=.

20?.

210.

b) /nmana ed code d5afe code 4444444 is a mem(er t#at ena('es an o(Gect or c'ass to .ro)ide +1.0, notifications. a<e'egate c) An D"ent (n /ndeFers dconstructor. 5tatement /: /ndeFers s#ou'd (e used on'3 in situations "#ere t#e +1.5, a(straction maEes sense. 5tatement //: /ndeFers s#ou'd #a)e (ot# a getter and setter! as arra3s are read8"rite o(Gects. a- 5tatement / is true. c- >ot# t#e statements are true. b) 3tatement ,, is true. d- >ot# t#e statements are fa'se. 5tatement /: .ro.ert3 can (e a static mem(er! "#ereas an +1.5, indeFer is a'"a3s an instance mem(er. 5tatement //: get accessor of an indeFer corres.onds to a met#od "it# no .arameters. &#ic# of t#e a(o)e statements are true* a- 5tatement / is true. c- >ot# t#e statements are true. b) 3tatement ,, is true. d- >ot# t#e statements are fa'se. @or defining t#e de'egate "#ic# of t#e fo''o"ing entities must (e +1.5, s.ecified* a- name of t#e eac# met#od c) return t#!es of each method (- access modifier of eac# met#od d) !arameters used b# each method 1. c'ass Test$ +1.5, 2. de'egate )oid 5im.'e<e'egate1-2 3. static )oid @1- $ A. 53stem.Conso'e.&riteBine16Test.@7-2 5. % :. static )oid Dain1- $ ;. 5im.'e<e'egate d 0 ne" 5im.'e<e'egate1@-2 =. d1-2 ?. % 10. % &#at "i'' (e t#e out.ut of a(o)e code "#en com.i'ed8run* a- T#e code "i'' generate a com.i'e time c- T#e code "i'' error at 'ine = as no .arameters are generate a runtime .assed to t#e de'egate. error since nu'' )a'ue is referenced.

211.

212.

b)

213.

21A.

d- T#e code "i'' com.i'e successfu''3 (ut "i'' not dis.'a3 an3t#ing on standard out.ut. de'egate instance enca.su'ates one or more met#ods! eac# of +1.5, "#ic# is referred to as a _________ a- <e'egated met#od c- Du'ti ca'' met#od b) Callable entit# >>935( d- /n)oca('e met#od 5tatement /: T#e ne" modifier is on'3 .ermitted on de'egates dec'ared +1.5, "it#in anot#er t3.e 5tatement //: T#e ne" modifier a..'ied on de'egate o)errides t#e met#od for "#ic# t#e de'egate is (eing used. 5tatement ///: T#e ne" modifier a..'ied on de'egates #ides in#erited mem(er (3 t#e same name. &#ic# of t#e a(o)e statements are true. a) Inl# statement ,, is true.

&he code will com!ile successfull# and the out!ut of abo"e code will be$ &est.+

c- 5tatement /// and / are true. (- 5tatement // and /// are true. d- 5tatement // and / are true. 215. To dec'are a "e( ser)ice t#e c'ass must in#erit from 4444444444 a- 53stem.&e(5er)ice. c) 3#stem.Web.3er"ice (- 53stem.5er)ices d 53stem!&e( 21:. T"o t3.es of de'egates are: a) 3in le Cast dele ate c) 9ulti Cast dele ate. (dda('e de'egate d- Du'ti 'e)e' <e'egate 21;. &#ic# of t#e fo''o"ing statements are true a(out de'egates a) A dele ate can be thou ht of as a c) ,t cannot be used t#!e1safe obBect1oriented function for e"ent handlin . !ointer. b) ,t can handle onl# one method at a d- /t a''o"s t#e time. in)ocation of a met#od "it#out t#e need for inner-c'ass ada.ters. 21=. &#ic# of t#e fo''o"ing statements are true* an indeFer t#at inc'udes t#e o)erride c- T#e a(stract modifier modifier ma3 a'so inc'ude t#e sea'ed can (e used on modifier. indeFers (ut not t#e modifier o)erride. b) An inde*er element can be classified d) &he o"erridden as "ariable. inde*er must differ from the si natures of all other inde*ers

+1.5,

+1.5, +1.5,

+2.0,

declared in the same class. 21?. c'ass Question$ .u('ic Ras#ta('e <irector3 0 ne" Ras#ta('e1-2 .u('ic string t#is+string Person, $ get $ return 1string- <irector3+Person,2 % set $ <irector3+Person, 0 )a'ue2 % % % c'ass Test $ static )oid Dain1- $ Question <ir 0 ne" Question1-2 88 dd code #ere. . . . . . . . % % +2.0,

220.

221.

T"o .ersons named 5D/TR and D QT/N are to (e added in t#e director3 created a(o)e. To ac#ie)e t#is "#ic# of t#e fo''o"ing are t#e )a'id statements t#at can (e added in t#e s.ace s.ecified in t#e code a(o)e* a- <irector3 +657,075D/TR72 <irector3 c) 5ir 6K3L7=L39,&-L; +6D7,07D QT/N72 5ir 6K9L7=L9AC&,(L; (- <irector3 +65D/TR7,07572 <irector3 d- <ir +65D/TR7,2 <ir +6D QT/N7,07D72 +6D QT/N7,2 &#ic# of t#e fo''o"ing are true "it# res.ect to de'egates* 88D5<N +2.0, a) +or static methods, a callable entit# d- T"o different consists of Bust a method. de'egates t3.es t#at #a)e t#e same signature and return t3.e are not considered different de'egate t3.es. b) 5ele ate t#!es are im!licitl# sealed e- <e'egate t3.es in C# are not name eWui)a'ent! (ut structura''3 eWui)a'ent. c) ,t is not !ermissible to deri"e an# t#!e from a dele ate t#!e. &#ic# of t#e fo''o"ing statements are true* +2.0, a) +or a non1multicast dele ate c) +or a multi1cast instance, the in"ocation list consists dele ate, the of the dele ate instance itself. in"ocation list is formed b#

(-

<e'egates can (e com(ined using t#e concatenation o.erators

d-

concatenatin the in"ocation lists of the two o!erands of the addition o!eration that formed the multi1 cast dele ate. <e'egate can (e remo)ed from anot#er t3.e using t#e de'ete o.erator. +2.0,

222.

c'ass Question$ de'egate )oid <e'egate1-2 static )oid @oo1- $ 53stem.Conso'e.&riteBine1CRe''oC-2 % static )oid Dain1- $ <e'egate d 0 ne" <e'egate1@oo-2 Question t0ne" Question1-2 t.Du'tiCa''1d!3-2 % )oid Du'tiCa''1<e'egate d! int count- $ for 1int i 0 02 i Y count2 iXXd1-2 % %

223.

&#at "i'' (e t#e out.ut of a(o)e code "#en com.i'ed8run* a- T#e code "i'' generate a com.i'e time c) &he code will com!ile error as no .arameters are .assed to t#e successfull# and de'egate "#en ca''ed. dis!la# followin lines on the standard out!ut$ -ello -ello -ello (- T#e code "i'' generate a runtime error d- T#e code "i'' com.i'e since nu'' )a'ue is referenced. successfu''3 (ut "i'' not dis.'a3 an3t#ing on standard out.ut. &#ic# of t#e fo''o"ing statements correct'3 differentiates (et"een de'egate +2.0, and an interface* a- <e'egates can (e used "it#out t#e c- Tn'iEe interfaces o(Gect reference (ut interface cannot (e. de'egates remain in memor3 fore)er. b) ,n an interface the method name is d) ,nterface cannot be

fi*ed, whereas with a dele ate onl# the si nature is fi*ed. 22A. &#ic# of t#e fo''o"ing statements re true* a) ,t is not !ermissible to deri"e a non1 dele ate class t#!e from System.Delegate. c-

instantiated but dele ates can be instantiated. +2.0,

225.

22:.

/t is .ossi('e to access mem(ers of t#e 53stem.<e'egate t3.e )ia t#e usua' mem(er access s3ntaF. (- 53stem.<e'egate is an interface t3.e d) Ince instantiated, t#at a'' de'egate t3.es deri)es. dele ate instances alwa#s refers to the same tar et obBect and method ssuming t#at / #a)e se)era' c'ients "#o "ou'd 'iEe to recei)e notification "#en a .articu'ar e)ent occurs. Putting a'' of t#em in a 444444 t3.e of de'egate can #e'. ca'' a'' t#e c'ients "#en a .articu'ar e)ent occurs. a- 5ing'e Cast de'egate c) 9ulti Cast dele ate. (dda('e de'egate d- Du'ti 'e)e' <e'egate .u('ic de'egate (oo' <e'egateName1.aram1!.aram2-

+2.0,

+2.0,

22;.

5tatement /: &#en t#e com.i'er com.i'es t#e statement a(o)e! it interna''3 generates a ne" c'ass t3.e. 5tatement //: &#en com.i'er com.i'es t#e statement a(o)e! it interna''3 generates <e'egateName c'ass. &#ic# of t#e a(o)e statements are true* a) %oth the statements are true. c- 5tatement / is true (- 5tatement // is true d- >ot# t#e statements are fa'se. &#at is "rong "it# t#e fo''o"ing code* +2.0, 88Tnsafe code ma3 on'3 a..ear if com.i'ing "it# 8unsafe .u('ic unsafe struct Node $ .u('ic int [a'ue2 .u('ic Node_ Beft2 .u('ic Node_ Qig#t2 % a- T#e 6unsafe7 Ee3"ord s#ou'd .recede c) (othin is wron t#e .u('ic modifier in t#e struct with the abo"e code. dec'aration a(o)e. (- [aria('es Beft and Qig#t #a)ing data d- Pointers cannot (e t3.e 6.ointer7 must (e dec'ared as used in t#e struct data 6unsafe7. t3.e. 88Tnsafe code ma3 on'3 a..ear if com.i'ing "it# 8unsafe

22=.

+2.0,

.u('ic c'ass $ .u('ic unsafe )irtua' )oid @1- $ c#ar_ .2 % % .u('ic c'ass >: $ .u('ic o)erride )oid @1- $ (ase.@1-2 % % &#at is "rong "it# t#e a(o)e code* a- Not#ing is "rong "it# t#e a(o)e code. c@unction .@1 - cannot (e o)er'oaded since it is dec'ared as 6unsafe7. T#e function >.@1 must (e dec'ared as 6unsafe7. +2.5,

(22?.

T#e 6unsafe 6 Ee3"ord must (e s.ecified d"#i'e ca''ing a function .@1 - in t#e c'ass > using 53stem2 c'ass /nt/ndeFer$ .ri)ate string+, m3<ata2 .u('ic /nt/ndeFer1int siVe- $ m3<ata 0 ne" string+siVe,2 for 1int i002 i Y siVe2 iXX- $ m3<ata+i, 0 CEm.t3C2 % % .u('ic string t#is+int .os, $ get $ return m3<ata+.os,2 % set $ m3<ata+.os, 0 )a'ue2 % % static )oid Dain1string+, args- $ /nt/ndeFer m3/nd 0 ne" /nt/ndeFer15-2 m3/nd+1, 0 C5ome [a'ueC2 m3/nd+A, 0 C n3 [a'ueC2 m3/nd+2, 0 C not#er [a'ueC2 Conso'e.&riteBine1Cbn/ndeFer Uut.utbnC-2 for 1int i002 i Y 52 iXX- $ Conso'e.&riteBine1Cm3/nd+$0%,: $1%C! i! m3/nd+i,-2

% % % &#at "i'' (e t#e out.ut of a(o)e code* a- 5ome [a'ue not#er [a'ue n3 [a'ue (5ome [a'ue n3 [a'ue not#er [a'ue

c)

d-

Dm!t# 3ome Malue Another Malue Dm!t# An# Malue 5ome [a'ue Em.t3 not#er [a'ue Em.t3 n3 [a'ue +2.5,

230.

using 53stem2 de'egate )oid 5tereot3.e1-2 c'ass C merican $ .u('ic )oid >ePatriotic1$ Conso'e.&riteBine 16 merica.C-2 % % c'ass C>rit$ .u('ic )oid >eceno.#o(ic1$ Conso'e.&riteBine1 CRe''oC -2 % % .u('ic static )oid Dain1- $ C merican c#ucE 0 ne" C merican1-2 C>rit ed"ard 0 ne" C>rit1-2 5tereot3.e+, stereot3.es 0 ne" 5tereot3.e+2,2 stereot3.es+0, 0 ne" 5tereot3.e1 c#ucE.>ePatriotic -2 stereot3.es+1, 0 ne" 5tereot3.e1 ed"ard.>eceno.#o(ic -2 foreac#1 5tereot3.e s in stereot3.es s1-2 % % &#at "i'' (e t#e out.ut of a(o)e code "#en com.i'ed 8run* a- T#e code generates an error as "#en c- T#e code generates an de'egate 5tereot3.e is instantiated. error! as de'egate arra3 is not a''o"ed in C#.

b)

231.

&he code will com!ile successfull# d- T#e code "i'' com.i'e and out!ut of the code will be$ successfu''3 (ut America generates a run time -ello error. using 53stem2 +2.5, .u('ic de'egate (oo' D3<e'egate1o(Gect sendingo(G! /nt32 F-2 .u('ic c'ass Test<e'egateC'ass $ static (oo' D3@unction1o(Gect sendingo(G! /nt32 F- $ if 1FY100- $ return true2 %e'se return fa'se2 % .u('ic static )oid Dain1- $ D3<e'egate mdg 0 ne" D3<e'egate1D3@unction-2 Test<e'egateC'ass tdc 0 ne" Test<e'egateC'ass1-2 53stem.Conso'e.&riteBine1mdg1ne" Test<e'egateC'ass1-!100--2 % % &#at "i'' (e t#e out of a(o)e code "#en com.i'ed and run* a) &he code will com!ile successfull# and out!ut of the code will +alse (- T#e code "i'' com.i'e successfu''3 and d- T#e code generates an out.ut of t#e code "i'' error! as >oo'ean True return t3.e for de'egates is not a''o"ed in C#. c'ass /ndeFerTest $ +2.5, .u('ic int )ar1!)ar22 .u('ic int t#is+int indeF, $ get $ if 1indeF001return )ar12 e'se return )ar22 % set $ if 1indeF001)ar10)a'ue2 e'se )ar20)a'ue2 % % % c'ass Test $ static )oid Dain1- $

232.

/ndeFerTest /ndeFDe 0 ne" /ndeFerTest1-2 /ndeFDe+1, 0 1002 /ndeFDe+2, 0 10002 53stem.Conso'e.&riteBine1/ndeFDe+1,-2 53stem.Conso'e.&riteBine1/ndeFDe+2,-2 53stem.Conso'e.&riteBine1/ndeFDe+3,-2 % % &#at "i'' (e t#e out.ut of a(o)e code "#en com.i'e8run* a- 100 c- 1000 100 100 1000 1000 (- 1000 d) 100 1000 1000 100 1000 c'ass /ndeFEFam.'e$ string Dessage2 .u('ic static )oid Dain1- $ /ndeFEFam.'e o(G0ne" /ndeFEFam.'e1C&EBCUDEC-2 for1int i002i Y ;2iXX- $ 53stem.Conso'e.&rite1o(G+i,-2 % % .u('ic /ndeFEFam.'e1string s- $ Dessage0s2 % .u('ic string t#is+int i, $ get $ if1i >0 0 dd i Y Dessage.Bengt#return Dessage.5u(string1i!1-2 e'se return CC2 % set $ if1i >0 0 dd i Y Dessage.Bengt#Dessage0Dessage.5u(string10!i- X )a'ue X Dessage.5u(string1iX1-2 % % % &#at "i'' (e t#e out.ut of a(o)e code* a- Code "i'' generate a com.i'e time error. b) &he code will com!ile successfull# and out!ut will be$ cCode "i'' generate a run time error.

233.

+2.5,

23A.

WD:CI9D c'ass summing $ .u('ic int tota'0?2 .u('ic int t#is+int first!int second, $ get $ return tota'2 % set $ tota'0firstXsecond2 % % .u('ic static )oid Dain1-$ summing sum10ne" summing1-2 int tota'002 88 add code #ere Z.. % % &#ic# of t#e fo''o"ing code must (e added to find t#e tota' of 100 and 200 and .rint t#e ans"er using a(o)e code* a- tota'0 sum1+100!200,2 c- sum1+100!200,0tota'2 53stem.Conso'e.&riteBine1tota'-2 53stem.Conso'e.&rite Bine1tota'-2 (- sum16100,8007=total; d- sum11 100!200 -0tota'2 3#stem.Console.Write:ine(sum1610,8 53stem.Conso'e.&rite 07); Bine1sum11 10!20 --2 using 53stem.Co''ections2 c'ass /ndeFing$ .u('ic Ras#ta('e <ictionar3 0 ne" Ras#ta('e1-2 .u('ic string t#is+string Name, $ get $ return 1string- <ictionar3+Name,2 % set $ <ictionar3+Name, 0 )a'ue2 % % % c'ass Test $ static )oid Dain1- $ /ndeFing /ndeF1 0 ne" /ndeFing1-2 /ndeF1+CC C, 0 CC B/@UQN/ C2 /ndeF1+C DC, 0 C DEQ/C C2

+2.5,

235.

+2.5,

53stem.Conso'e.&riteBine1/ndeF1+C DEQ/C C,-2 % % &#at "i'' (e t#e out.ut of a(o)e code "#en com.i'ed8run* a- T#e code "i'' generate a com.i'e time c) &he code will com!ile error. successfull# but does not dis!la# an# out!ut. (- T#e code "i'' com.'ie successfu''3 and d- T#e code "i'' com.i'e out.ut of code "i'' (e: successfu''3 and DEQ/C out.ut of code "i'' (e: D

You might also like