TstLin - SCJP smpl 2 Mint fltsor vnég Kérésk szám: 30 kérés Kitöltési iő: 1:11:48 Pont gység: +6-2 Értéklés: Alpértlmztt értéklés Típus: Minig vn lglá gy jó válsz (N/1..N) Sour: http://sjptst.om 1. Givn th o. Wht is th rsult? [sour:jv] import jv.io.*; Sriliztion 2:42 puli lss Hotl implmnts Srilizl { privt Room room = nw Room(); puli stti voi min(string[] rgs) { Hotl h = nw Hotl(); try { FilOutputStrm fos = nw FilOutputStrm("Hotl.t"); OjtOutputStrm oos = nw OjtOutputStrm(fos); oos.writojt(h); oos.los(); th(exption x) { x.printstktr(); lss Room { [sour] An xption is thrown t runtim. An instn of Hotl is sriliz. Compiltion fils. An instn of Hotl n n instn of Room r oth sriliz. TstLin - SCJP smpl 2 oll 1/19 Mint fltsor
TstLin - SCJP smpl 2 Mint fltsor vnég 2. Givn th o. Wht is th rsult? [sour:jv] puli stti voi min(string rgs[]) { String str = "null"; if (str == null) { Systm.out.print("1"); ls if (str.lngth() == 0) { Systm.out.print("2"); ls { Systm.out.print("3"); [sour] Cor 1:07 "1" is print. Compiltion fils. "2" is print. An xption is thrown t runtim. "3" is print. 3. Givn: is vli, non-null jv.util.dt ojt f is vli, non-null jv.txt.dtformt ojt st to th urrnt lol. Wht outputs th urrnt lol's ountry nm n th pproprit vrsion of t? [sour:jv] Lol l = Lol.gtDfult(); Systm.out.println(l.gtDisplyCountry() + " " + f.stdtformt()); [sour] [sour:jv] Lol l = Lol.gtLol(); Systm.out.println(l.gtDisplyCountry()); [sour] [sour:jv] Lol l = Lol.gtDfult(); Systm.out.println(l.gtDisplyCountry() + " " + f.formt()); [sour] [sour:jv] Lol l = Lol.gtLol(); Systm.out.println(l.gtDisplyCountry() + " " + f.stdtformt()); [sour] Clnr 2:39 TstLin - SCJP smpl 2 oll 2/19 Mint fltsor
TstLin - SCJP smpl 2 Mint fltsor vnég 4. Wht o you n to o to orrt ompiltion rrors? (Slt two) [sour:jv] puli lss Crtur { privt int lgcount; privt int wingcount; Cor 2:57 puli Crtur(int lgcount) { this.lgcount = this.lgcount; this.wingcount = 0; puli String tostring() { rturn "lgs=" + this.lgcount + " wings=" + wingcount; puli lss Animl xtns Crtur { puli Animl(int lgcount) { this.wingcount = 0; [sour] f hng th wingcount vril in th lss Crtur to prott. insrt ll to supr(lgcount) into Animl onstrutor. hng th string "this.wingcount = 0" in th lss Animl to "supr.wingcount = 0" insrt ll to supr() into Crtur onstrutor. insrt ll to supr() into Animl onstrutor. insrt ll to this() into Animl onstrutor. TstLin - SCJP smpl 2 oll 3/19 Mint fltsor
TstLin - SCJP smpl 2 Mint fltsor vnég 5. Colltion 2:38 Givn th o. Wht is th rsult? [sour:jv] import jv.util.colltions; import jv.util.linklist; puli lss TryM { puli stti voi min(string rgs[]) { LinkList list = nw LinkList(); list.("bb1"); list.("b2"); list.("b3"); list.("bb4"); Colltions.sort(list); for (String str : list) { Systm.out.print(str + ":"); [sour] f "BB4:BB1:B2:B3:" is print. "BB4:B3:B2:BB1:" is print. "B3:B2:BB1:BB4:" is print An xption is thrown t runtim. Compiltion fils. "BB1:B2:B3:BB4:" is print. TstLin - SCJP smpl 2 oll 4/19 Mint fltsor
TstLin - SCJP smpl 2 Mint fltsor vnég 6. Givn th o. Wht is th rsult? [sour:jv] puli stti voi min(string rgs[]) { try { String rr[] = nw String[10]; rr = null; rr[0] = "on"; Systm.out.print(rr[0]); th(exption x) { Systm.out.print("xption"); th(nullpointrexption nx) { Systm.out.print("null pointr xption"); [sour] Exption 2:16 "xption" is print. Compiltion fils. "null pointr xption" is print. "on" is print. 7. Givn th o. Wht is th rsult? [sour:jv] puli lss Hotl { Thr 2:09 privt stti voi ook() { Systm.out.print("ook"); puli stti voi min(string[] rgs) { Thr.slp(1); ook(); [sour] An xption is thrown t runtim. "ook" is print. Th o xuts normlly, ut nothing is print. Compiltion fils. TstLin - SCJP smpl 2 oll 5/19 Mint fltsor
TstLin - SCJP smpl 2 Mint fltsor vnég 8. Givn th o. Whih lin of o mrks th rlist point tht n ojt rfrn y myint oms nit for grg olltion? [sour:jv] puli voi ostuff() { Intgr rr[] = nw Intgr[5]; for (int i = 0; i < rr.lngth; i++) { Intgr myint = nw Intgr(i); rr[i] = myint; Systm.out.println("n"); [sour] GC 2:09 Lin 6 Lin 7 Lin 5 Lin 4 9. Giv pi of o. Wht is tru? [sour:jv] puli voi witforsomthing() { SomClss o = nw SomClss(); synhroniz (o) { o.wit(); o.notify(); [sour] Thr 2:11 This o my throw n IntrruptExption Rvrsing th ofrr of o.wit() n o.notify() will us this mtho to omplt normlly. This o my throw n IllglSttExption This o my throw TimOutExption TstLin - SCJP smpl 2 oll 6/19 Mint fltsor
TstLin - SCJP smpl 2 Mint fltsor vnég 10. Gnri 2:23 Givn th o. Wht is th rsult? [sour:jv] puli lss TrikyNum { privt X x; puli TrikyNum(X x) { this.x = x; privt oul gtdoul() { rturn x.oulvlu(); puli stti voi min(string rgs[]) { TrikyNum = nw TrikyNum(nw Intgr(1)); Systm.out.print(.gtDoul()); [sour] Compiltion fils. "1" is print. An xption is thrown t runtim. "1.0" is print. TstLin - SCJP smpl 2 oll 7/19 Mint fltsor
TstLin - SCJP smpl 2 Mint fltsor vnég 11. Givn th o. Wht is th rsult? [sour:jv] lss Vhil { puli voi printsoun() { Systm.out.print("vhil"); Cor 2:42 lss Cr xtns Vhil { puli voi printsoun() { Systm.out.print("r"); lss Bik xtns Vhil { puli voi printsoun() { Systm.out.print("ik"); puli lss Tst { puli stti voi min(string[] rgs) { Vhil v = nw Cr(); Bik = (Bik) v; v.printsoun();.printsoun(); [sour] f "vhilik" is print. Compiltion fils. An xption is thrown t runtim. "vhilr" is print. "rr" is print. "ikik" is print TstLin - SCJP smpl 2 oll 8/19 Mint fltsor
TstLin - SCJP smpl 2 Mint fltsor vnég 12. Givn th o. Wht is th output? [sour:jv] puli lss Tst { int = 10; Prmtr 2:02 puli voi ostuff(int ) { += 1; Systm.out.println(++); puli stti voi min(string rgs[]) { Tst t = nw Tst(); t.ostuff(3); [sour] 5 4 11 12 13. Givn th o. Wht is th rsult? [sour:jv] String tst = "This is tst string"; String[] tokns = tst.split("\\s"); Systm.out.println(tokns.lngth); [sour] String 1:53 5 An xption is thrown t runtim Compiltion fils 21 0 TstLin - SCJP smpl 2 oll 9/19 Mint fltsor
TstLin - SCJP smpl 2 Mint fltsor vnég 14. f 15. f 16. f g h Whih thr will ompil without xption? (Choos thr) voi ook() { synhroniz () { puli voi ook() { synhroniz(cruisr.lss) { puli synhroniz(this) voi ook() { puli voi ook() {synhroniz(){ puli synhroniz voi ook() { privt synhroniz SomClss ; Somon is writing lss MyKy, tht will us s ky in th jv.util.hshmp. Whih mthos shoul ovrrin to gurnt tht MyKy works s HshMp ky? (Slt ll tht pply) puli int hshco() puli int hs() puli int omprto(ojt) puli ooln quls(ojt) puli int omprto(myky) puli ooln quls(myky) A Jv n omponnt hs th following fil: privt ooln on; Whih mtho lrtions follow th JvBn stnrs for gtting/sttings this fil? (Choos 3) puli ooln isdon() puli voi stdon(ooln on) puli voi stdon() puli voi isdon() puli ooln gtdon() puli ooln gtdon(ooln on) privt ooln stdon(ooln on) puli ooln stdon(ooln on) Thr 1:59 Hsh 2:04 Jv n 2:10 TstLin - SCJP smpl 2 oll 10/19 Mint fltsor
TstLin - SCJP smpl 2 Mint fltsor vnég 17. Givn th o. Wht is th rsult? [sour:jv] import jv.io.*; Sriliztion 2:43 puli lss Hotl implmnts Srilizl { privt trnsint Room room = nw Room(); puli stti voi min(string[] rgs) { Hotl h = nw Hotl(); try { FilOutputStrm fos = nw FilOutputStrm("Hotl.t"); OjtOutputStrm oos = nw OjtOutputStrm(fos); oos.writojt(h); oos.los(); th(exption x) { x.printstktr(); lss Room { [sour] An xption is thrown t runtim. Compiltion fils. An instn of Hotl n n instn of Room r oth sriliz. An instn of Hotl is sriliz. 18. Wht is tru out hs- n is- rltionships? (Choos two) Inhritn rprsnts hs- rltionship. Inhritn rprsnts n is- rltionship. Instn vrils n us whn rting hs- rltionship. Instns must us whn rting hs- rltionship. Thory 1:57 TstLin - SCJP smpl 2 oll 11/19 Mint fltsor
TstLin - SCJP smpl 2 Mint fltsor vnég 19. Thr 2:59 Giv pi of o. Whih two r possil rsults? (Slt two) [sour:jv] puli lss Cruisr { privt int = 0; puli voi foo() { Runnl r = nw LittlCruisr(); nw Thr(r).strt(); nw Thr(r).strt(); puli stti voi min(string rg[]) { Cruisr = nw Cruisr();.foo(); puli lss LittlCruisr implmnts Runnl { puli voi run() { int urrnt = 0; for (int i = 0; i < 4; i++) { urrnt = ; Systm.out.print(urrnt + ", "); = urrnt + 2; [sour] 0, 2, 4, 6, 8, 10, 2, 4, 0, 2, 4, 0, 2, 4, 6, 6, 0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14, 0, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14, 0, 2, 4, 6, 8, 10, 12, 14, 20. Givn: [sour:jv] Systm.out.printf("Pi = %f n E = %", Mth.PI, Mth.E); [sour] Wht is th output? Cor 1:46 TstLin - SCJP smpl 2 oll 12/19 Mint fltsor
TstLin - SCJP smpl 2 Mint fltsor vnég 21. Whih thr sttmnts onrning th us of th jv.io.srilizl intrf r tru? (Choos thr) Th vlus in fils with th voltil moifir will not surviv sriliztion n sriliztion. An ojt sriliz on on JVM n sriliz on iffrnt JVM. ojt from lsss th us ggrgtion nnot sriliz. Th vlus in fil with th trnsint moifir will not surviv sriliztion n sriliztion. It is lgl to sriliz n ojt of typ tht hs suprtyp tht os not implmnt jv.io.srilizl Sriliztion 2:24 22. Givn th o. Wht is th rsult? [sour:jv] DtFormt f = DtFormt.gtDtInstn(); f.stlol(lol.us); Clnr = Clnr.gtInstn();.st(Clnr.YEAR, 2009);.st(Clnr.MONTH, 5);.st(Clnr.DAY_OF_MONTH, 1); String formttdt = f.formt(.gttim()); Systm.out.println(formttDt); [sour] Clnr 2:12 Jun 1, 2009 Compiltion fils July 1, 2009 An xption is thrown t runtim TstLin - SCJP smpl 2 oll 13/19 Mint fltsor
TstLin - SCJP smpl 2 Mint fltsor vnég 23. Colltion 2:55 Givn th o. Wht is th rsult? [sour:jv] import jv.util.colltions; import jv.util.linklist; import jv.util.list; puli lss HshTst { privt String str; puli HshTst(String str) { this.str = str; @Ovrri puli String tostring() { rturn this.str; puli stti voi min(string rgs[]) { HshTst h1 = nw HshTst("2"); String s1 = nw String("1"); List list = nw LinkList(); list.(h1); list.(s1); Colltions.sort(list); for (Ojt o : list) { Systm.out.print(o + " "); [sour] "2 1" is print. "1 2" is print. Compiltion fils. An xption is thrown t runtim. TstLin - SCJP smpl 2 oll 14/19 Mint fltsor
TstLin - SCJP smpl 2 Mint fltsor vnég 24. f g 25. f A vlopr is rting lss A, tht ns to ss lss B. Th B lss is ploy in jr nm suprli.jr. Whih thr, will llow th vlopr to us th B lss whil ompiling th A lss. (hoos thr) Thory 3:09 Th jr fil is lot t /myfolr/suprli.jr n th A lss is ompil using "jv - /myfolr/suprli.jr A.jv" Th jr fil is lot t $JAVA_HOME/jr/li/xt/suprLi.jr Th jr fil is lot t /myfolr/suprli.jr n th A lss is ompil using "jv -lsspth /myfolr/suprli.jr A.jv" Th jr fil is lot t /myfolr/suprli.jr n lsspth nvironmnt vril is st tht inlus /myfolr/suprli.jr Th jr fil is lot t $JAVA_HOME/jr/lsss/suprLi.jr Th jr fil is lot t /myfolr/suprli.jr n th A lss is ompil using "jv -p /myfolr/suprli.jr/b A.jv" Th jr fil is lot t /myfolr/suprli.jr n lsspth nvironmnt vril is st tht inlus /myfolr/suprli.jr/b.lss Wht is tru? (Choos thr) A puli stti mtho in lss Z n ll y sulss of Z without xpliitly rfrning th lss Z. A finl mtho in lss Z n strt if n only if Z is strt. A prott mtho in lss Z n ovrrin y ny sulss of Z. A privt stti mtho n ll only within othr stti mthos in lss Z. A non-stti puli finl mtho in lss Z n ovrrin in ny sulss of Z. A mtho with th sm signtur s privt finl mtho in lss Z n implmnt in sulss of Z. Thory 2:25 TstLin - SCJP smpl 2 oll 15/19 Mint fltsor
TstLin - SCJP smpl 2 Mint fltsor vnég 26. Givn th o. Wht is th rsult? [sour:jv] import jv.util.arrys; Colltion 2:45 puli lss HshTst { privt String str; puli HshTst(String str) { this.str = str; @Ovrri puli String tostring() { rturn this.str; puli stti voi min(string rgs[]) { HshTst h1 = nw HshTst("2"); String s1 = nw String("1"); Ojt rr[] = nw Ojt[2]; rr[0] = h1; rr[1] = s1; Arrys.sort(rr); for (Ojt o : rr) { Systm.out.print(o + " "); [sour] Compiltion fils. "2 1" is print. An xption is thrown t runtim. "1 2" is print. TstLin - SCJP smpl 2 oll 16/19 Mint fltsor
TstLin - SCJP smpl 2 Mint fltsor vnég 27. Givn th o. Wht is th rsult? [sour:jv] int i = 10; whil (i++ Cor 2:16 13 10 Lin 5 will nvr rh. 12 11 28. Givn th o. Wht is th rsult? [sour:jv] lss Hotl { puli voi ook() throws Exption { throw nw Exption(); Ovrri 2:50 puli lss SuprHotl xtns Hotl { puli voi ook() { Systm.out.print("ook"); puli stti voi min(string rgs[]) { Hotl h = nw SuprHotl(); h.ook(); [sour] Th o runs without ny output. Compiltion fils. "ook" is print. An xption is thrown t runtim. TstLin - SCJP smpl 2 oll 17/19 Mint fltsor
TstLin - SCJP smpl 2 Mint fltsor vnég 29. Givn th o. Wht is th rsult? [sour:jv] import jv.io.*; Sriliztion 2:44 puli lss Hotl implmnts Srilizl { privt Room room = nw Room(); puli stti voi min(string[] rgs) { Hotl h = nw Hotl(); try { FilOutputStrm fos = nw FilOutputStrm("Hotl.t"); OjtOutputStrm oos = nw OjtOutputStrm(fos); oos.writojt(h); oos.los(); th(exption x) { x.printstktr(); lss Room implmnts Srilizl { [sour] An instn of Hotl is sriliz. Compiltion fils. An xption is thrown t runtim. An instn of Hotl n n instn of Room r oth sriliz. TstLin - SCJP smpl 2 oll 18/19 Mint fltsor
Powr y TCPDF (www.tpf.org) TstLin - SCJP smpl 2 Mint fltsor vnég 30. Givn th o. Wht is th rsult? [sour:jv] lss Vhil { puli voi printsoun() { Systm.out.print("vhil"); Vhil 2:42 lss Cr xtns Vhil { puli voi printsoun() { Systm.out.print("r"); lss Bik xtns Vhil { puli voi printsoun() { Systm.out.print("ik"); puli lss Tst { puli stti voi min(string[] rgs) { Vhil v = nw Cr(); Cr = (Cr) v; v.printsoun();.printsoun(); [sour] f "ikik" is print An xption is thrown t runtim. "vhilik" is print. "vhilr" is print. Compiltion fils. "rr" is print. TstLin - SCJP smpl 2 oll 19/19 Mint fltsor