You are on page 1of 16

Trc nghim JaVa - Bi 08

Bi trc nghim v ngn ng Java cn bn ny s gip cc bn hiu thm c phn no v phng thc hot ng ca Java cng nh cch thc thi mt chng trnh ng dng c th trn ngn ng ny.

S cu: 10 im s cho mi cu: 1 nh du p n ng sai: ng: -- Sai: T l yu cu t: 75 % 1 - Cho bit kt qu sau khi bin dch v thi hnh chng trnh sau: 1 : public class Conditional{ 2 : public static void mai n(String[] args){ 3 : int x = 4; 4 : System.out.println("value is " + 5 : ((x > 4 ? 99.99 : 9)); 6:} 7:} [a]--Kt qu l: value is 99.99 [b]--Kt qu l: value is 9 [c]--Kt qu l: value is 9.0 [d]--Li bin dch ti dng s 5 2 - Cho bit kt qu ca on m sau: 1 : int x = 3; int y = 10; 2 : System.out.println(y % x); [a]--0 [b]--1 [c]--2 [d]--3 3 - Chn pht biu ng cho chng trnh sau 1 : class StaticStuff 2:{ 3 : static int x = 10; 4: 5 : static {x += 5;} 6: 7 : public static void main(String args[]) 8:{ 9 : System.out.pritln("x = " + x); 10 : } 11 :

12 : static {x /= 5} 13 : } [a]--Li bin dch ti dng 5 v 12 bi v thiu tn phng thc v kiu tr v [b]--Chng trnh chy v cho kt qu x = 10 [c]--Chng trnh chy v cho kt qu x = 15 [d]--Chng trnh chy v cho kt qu x = 3 4 - Chn cch sa t nht on m sau bin dch ng 3 : final class Aaa 4:{ 5 : int xxx; 6 : void yyy(){xxx = 1;} 7:} 8: 9: 10 : class Bbb extends Aaa 11 : { 12 : final Aaa finalRef = new Aaa(); 13 : 14 : final void yyy() 15 : { 16 : System.out.println("In method yyy()"); 17 : finalRef.xxx = 12345; 18 : } 19 : } [b]--Xo t final dng 1 [c]--Xa t final dng 1 v 10 [d]--Khng cn phi chnh sa g 5 - Chn pht biu ng cho chng trnh sau: 1 : class HasStatic 2:{ 3 : private static int x = 100; 4: 5 : public static void main(String args[]) 6:{ 7 : HasStatic hs1 = new HasStatic(); 8 : hs1.x++; 9 : HasStatic hs2 = new HasStatic(); 10 : hs2.x++; 11 : hs1 = new HasStatic(); 12 : hs1.x++; 13 : HasStatic.x++; 14 : System.out.println("x = " + x);

15 : } 16 : } [a]--Chng trnh chy v cho kt qu x = 102 [b]--Chng trnh chy v cho kt qu x = 103 [c]--Chng trnh chy v cho kt qu x = 104 [d]--Tt c cc cu trn u sai 6 - Cho on m sau: 1 : class SuperDuper 2:{ 3 : void aMethod(){} 4:} 5: 6 : class Sub extends SuperDuper 7:{ 8 : void aMethod(){} 9:} Hy chn t kha ch phm vi hp l ng trc aMethod() [a]--default [b]--protected [c]--public [d]--Tt c cc cu trn u ng 7 - on m sau dng cho 2 cu hi tip theo 1 : package abcde; 2: 3 : public class Bird{ 4 : protected static int referneceCount = 0; 5 : public Bird(){referenceCount++;} 6 : protected void fly(){} 7 : static int getRefCount(){return referenceCount;} 8:} Chn pht biu ng cho lp Bird trn v lp Parrot sau: 1 : package abcde; 2: 3 : class Parrot extends abcde.Bird{ 4 : public void fly(){ 5 : // 6:} 7 : public int getRefCount(){ 8 : return referenceCount;

9:} 10 : } [a]--Li bin dch dng 4 tp tin Parrot.java v phng thc fly() l protected trong lp cha v lp Bird v Parrot nm trong cng package [b]--Li bin dch dng 4 tp tin Parrot.java v phng thc fly() l protected trong lp cha v public trong lp con. [c]--Li bin dch dng 7 tp tin Parrot.java v phng thc getRefCount() l static trong lp cha. [d]--Chng trnh bin dch thnh cng nhng s pht sinh Exception khi chy nu phng thc fly() ca lp Parrot khng c gi 8 - Chn pht biu ng cho lp Bird trn v lp Nightingale sau: 1 : package singers; 2: 3 : class Nightingale extends abcde.Bird{ 4 : Nightingale(){ refernceCount++;} 5: 6 : public static void main(String args[]){ 7 : System.out.print("Before: " + refernceCount); 8 : Nightingale florence = new Nightingale(); 9 : System.out.print("After: " + refernceCount); 10 : florence.fly(); 11 : } 12 : } [a]--a. Kt qu trn mn hnh l: Before: 0 After: 2 [b]--Kt qu trn mn hnh l: Before: 0 After: 1 [c]--Li bin dch dng 4 ca lp Nightingale v khng th overidde thnh vin static [d]--Li bin dch dng 10 ca lp Nightingale v phng thc fly() l protected trong lp cha. 9 - Dng lnh no sau y s khng th bin dch: 1 : byte b = 5; 2 : char c = "5; 3 : short s = 55; 4 : int i = 555; 5 : float f = 555.5f; 6 : b = s; 7 : i = c; 8 : if (f > b) 9 : f = i; [a]--Dng 3 [b]--Dng 4 [c]--Dng 5 [d]--Dng 6

10 - Chn dng pht sinh li khi bin dch : 1 : byte b = 2; 2 : byte b1 = 3; 3 : b = b * b1; [a]--Dng 1 [b]--Dng 2 [c]--Dng 3 [d]--Tt c u ng Trc nghim JaVa - Bi 07
Bi trc nghim v ngn ng Java cn bn ny s gip cc bn hiu thm c phn no v phng thc hot ng ca Java cng nh cch thc thi mt chng trnh ng dng c th trn ngn ng ny.

S cu: 10 im s cho mi cu: 1 nh du p n ng sai: ng: -- Sai: T l yu cu t: 75 % Thi gian lm bi: 10 Pht. Thi gian cn li: 00:00 1 - Mn hnh sau s dng kiu trnh by no?

[a]--CardLayout [b]--nullLayout [c]--BorderLayout [d]--SetLayout 2 - Mn hnh sau s dng kiu trnh by no?

[a]--GridLayout [b]--FlowLayout [c]--BorderLayout [d]--GridBagLayout 3 - on m sau sai ch no?

[a]--on m khng c li [b]--iu kin ca cu lnh if phi c kiu boolean thay v Boolean [c]--Ch s ca cu lnh for l int thay v Integer [d]--Cu b v c ng 4 - Hy cho bit kt xut ca on chng trnh sau:

[a]--S1 [b]--S2 [c]--S1S2 [d]--S2S1 5 - Cho bit kt xut ca on chng trnh sau:

[a]--S1 [b]--S2 [c]--null [d]--S1S2

6 - Cho on m sau: 1 : class Q6{ 2 : public static void main(String args[]){ 3 : Holder h = new Holder(); 4 : h.held = 100; 5 : h.bump(h); 6 : System.out.println(h.held); 7:} 8:} 9 : class Holder{ 10 : public int held; 11 : public void bump(Holder theHolder){ 12 : theHolder.held++; 13 : } 14 : } Gi tr in ra ca cu lnh dng th 6 l: [a]--0 [b]--1 [c]--100 [d]--101 7 - Cho on m sau: 1 : class Q7{ 2 : public static void main(String args[]){ 3 : double d = 12.3; 4 : Decrementer dec = new Decrementer(); 5 : dec.decrement(d); 6 : System.out.println(d); 7:} 8:} 9 : class Decrementer{ 10 : public void decrement(double decMe){ 11 : decMe = decMe 1.0; 12 : } 13 : } Gi tr in ra ca cu lnh dng th 6 l: kh hiu qu????????? [a]--0.0 [b]---1.0 [c]--12.3 [d]--11.3 8 - on m no sau y in ra mn hnh ch "Equal": [a]--int x = 100; float y = 100.0F; if (x == y)

{ System.out.println("Equal"); } [b]--Integer x = new Integer(100); Integer y = new Integer(100); if (x == y) { System.out.println("Equal"); } [c]--String x = "100"; String y = "100"; if (x == y) { System.out.println("Equal"); } [d]--Cu a v c ng 9 - Cho bit kt qu sau khi thi hnh chng trnh sau: 1 : public class Short{ 2 : public static void main(String[] args){ 3 : StringBuffer s = new StringBuffer("Hello"); 4 : if ((s.length() > 5) && 5 : s.append(" there").equals("False"))) 6 : ;//do nothing 7 : System.out.println("value is " + s); 8:} 9:} [a]--Gi tr xut l Hello [b]--Li bin dch ti dng 4 v 5 [c]--Khng c gi tr xut [d]--Thng bo NullPointerException 10 - Cho bit kt qu sau khi thc hin chng trnh sau: 1 : public class Xor{ 2 : public static void main(String[] args){ 3 : byte b = 10;//00001010 4 : byte c = 15;//00001111 5 : b = (byte)(b ^ c); 6 : System.out.println("b contains " + b); 7:} 8:} [a]--Kt qu l: b contains 10 [b]--Kt qu l: b contains 5 [c]--Kt qu l: b contains 250 [d]--Kt qu l: b contains 245

5 - Trong on m sau kiu d liu ca bin result c th l [a]--int, long, float, double [b]--boolean, byte, short, char, int, long, float, double 6 - Mt kiu d liu s c du c 2 gi tr +0 v -0 bng nhau: [a]--ng [b]--Sai 7 - S kiu du chm ng khng c gi tr nh nht cng khng c gi tr ln nht. Chng c th nhn cc gi tr: - S m - S dng - V cc m - V cc dng [a]--ng [b]--Sai 8 - Java cung cp 2 kiu s nguyn khc nhau l: byte, Short. Kch thc, gi tr nh nht, ln nht, cng nh gi tr mc nh ca cc kiu d liu s nguyn c m t chi tit [a]--ng [b]--Sai 9 - Ngn ng lp trnh java c 8 kiu d liu c s: byte, short, int, long, float, double, boolean v char. [a]--ng [b]--Sai 10 - Trong ngn ng lp trnh java c phn bit ch in hoa v in thng khng ? [a]--C [b]--Khng Trc nghim JaVa - Bi 05
Bi trc nghim v ngn ng Java cn bn ny s gip cc bn hiu thm c phn no v phng thc hot ng ca Java cng nh cch thc thi mt chng trnh ng dng c th trn ngn ng ny.

S cu: 10 im s cho mi cu: 1 nh du p n ng sai: ng: -- Sai: T l yu cu t: 75 % Thi gian lm bi: 10 Pht. Thi gian cn li: 00:00 1 - Trong on m sau kiu d liu ca bin result c th l nhng kiu no? 1 : byte b = 11; 2 : short s =13; 3 : result = b * ++s;

[a]--byte, short, int, long, float, double [b]--boolean, byte, short, char, int, long, float, double [c]--byte, short, char, int, long, float, double [d]--int, long, float, double 2 - Chn pht biu ng : [a]--Tham chiu ca i tng c th c chuyn i trong php gn nhng khng th thc hin trong php gi phng thc [b]--Tham chiu ca i tng c th c p kiu trong php gi phng thc nhng khng th thc hin trong php gn [c]--Tham chiu ca i tng c th c chuyn i trong php gi phng thc v php gn nhng tun theo nhng quy tc khc nhau [d]--Tham chiu ca i tng c th c chuyn i trong php gi phng thc v php gn v tun theo nhng quy tc ging nhau 3 - Cho on m nh bn di. Hy cho bit dng no khng th bin dch 1 : Object ob = new Object(); 2 : String stringarr[] = new String[50]; 3 : Float floater = new Float(3.14f); 4 : ob = stringarr; 5 : ob = stringarr[5]; 6 : floater = ob; 7 : ob = floater; [a]--Dng 4 [b]--Dng 5 [c]--Dng 6 [d]--Dng 7 4 - Cho on m sau: 1 : for (int i = 0; i < 2; i++){ 2 : for (int j = 0; j < 3; j++){ 3 : if (i == j){ 4 : continue; 5:} 6 : System.out.println("i = " + i + "j = " + j); 7:} 8:} Dng no s l mt trong s cc kt qu c in ra? [a]--i = 0 j = 0 [b]--i = 0 j = 2 [c]--i = 2 j = 1 [d]--i = 1 j = 1 5 - Cho on m sau: 1 : outer: for (int i = 0; i < 2; i++){ 2 : for (int j =0; j < 3; j++){

3 : if (i == j){ 4 : continue outer; 5:} 6 : System.out.println("i = " + i + "j = " + j); 7:} 8:} Dng no s l mt trong s cc kt qu c in ra? [a]--i = 0 j = 0 [b]--i = 0 j = 1 [c]--i = 0 j = 2 [d]--i = 1 j = 0 6 - B qun l trnh by mc nh cho 1 khung cha kiu Panel l: [a]--FlowLayout [b]--BorderLayout [c]--GridLayout [d]--GridBagLayout 7 - Bn c th to ra ca s chnh ca ng dng bng cch gi: Frame f = new Frame("Main Frame"); Nhng khi bn chy chng trnh th Frame khng hin th. Dng no bn di s lm hin th Frame. [a]--f.setSize(300, 200); [b]--f.setBounds(10, 10, 500, 400); [c]--f.setForeground(Color.white); [d]--f.setVisible(true); 8 - i tng no bn di c th cha 1 menubar (chn nhng cu ng) [a]--Panel [b]--ScrollPane [c]--Frame [d]--Menu 9 - Sau khi to 1 frame bng cu lnh Frame f = new Frame() v to menu bar bng cu lnh MenuBar mb = new MenuBar(), lm th no gn MenuBar tn mb vo f [a]--f.add(mb) [b]--f.setMenu(mb) [c]--f.addMenu(mb) [d]--f.setMenuBar(mb) 10 - Cho on m sau : 1 :Racoon rocky; 2 :SwampThing pogo; 3 :Washer w; 4: 5 :rocky = new Racooon();

6 :w = rocky; 7 :pogo = w; [a]--Dng 6 s khng bin dch; cn phi c php p kiu chuyn t kiu Racoon sang kiu Washer [b]--Dng 7 s khng bin dch; cn c php p kiu chuyn t kiu Washer sang kiu SwampThing [c]--on m s bin dch nhng s pht sinh Exception dng 7 v chuyn i kiu khi thc thi t interface sang class l khng c php [d]--on m s bin dch v s pht sinh Exception dng 7 v kiu lp ca w ti thi im thc thi khng th chuyn sang kiu SwampThing Trc nghim JaVa - Bi 03
Bi trc nghim v ngn ng Java cn bn ny s gip cc bn hiu thm c phn no v phng thc hot ng ca Java cng nh cch thc thi mt chng trnh ng dng c th trn ngn ng ny.

S cu: 10 im s cho mi cu: 1 nh du p n ng sai: ng: -- Sai: T l yu cu t: 75 % Thi gian lm bi: 10 Pht. Thi gian cn li: 03:42 1 - Chn phng thc hin th Frame ln mn hnh : [a]--setVisible() [b]--display() [c]--displayFrame() [d]--Tt c cc cu trn u sai 2 - Chn pht biu ng [a]--Lp Class l lp cha ca lp Object [b]--Lp Object l mt lp final [c]--Mi lp k tha trc tip hoc gin tip t lp Object [d]--Tt c cc cu trn u sai 3 - Lp no sau y dng thc hin cc thao tc nhp xut c bn vi console : [a]--System [b]--Math [c]--String [d]--StringBuffer 4 - Lp no sau y khng phi l lp bao? [a]--Integer [b]--String [c]--Boolean [d]--Character

5 - Phng thc no sau y s lm cho gi tr bin s b thay i [a]--s.concat() [b]--s.toUpperCase() [c]--s.replace() [d]--Cu a v b ng 6 - Chn pht biu ng cho hm khi to [a]--Mt lp s kt tha cc hm khi to t lp cha [b]--Trnh bin dch s t ng to hm khi to mc nh nu lp khng nh ngha hm khi to [c]--Tt c cc hm khi to c kiu tr v l void [d]--Tt c cc cu trn u sai 7 - Mt kiu d liu s c du c 2 gi tr +0 v -0 bng nhau: [a]--ng [b]--Sai [c]--Ch ng vi kiu s nguyn [d]--Ch ng vi kiu s thc 8 - Chn khai bo tn ng : [a]--Big01LongStringWidthMeaninglessName [b]--$int [c]--bytes [d]--Tt c cc cu trn u ng 9 - Chn khai bo ng cho phng thc main() [a]--public static void main( ) [b]--public void main(String[] arg) [c]--public static void main(String[] args) [d]--public static int main(String[] arg) 10 - Chn th t ng ca cc thnh phn trong mt tp tin ngun : [a]--Cu lnh import, khai bo package, khai bo lp. [b]--Khai bo package u tin; th t ca cu lnh import v khai bo lp l ty . [c]--Khai bo package, cu lnh import, khai bo lp [d]--Cu lnh import trc tin; th t ca khai bo package v khai bo lp l ty . Trc nghim JaVa - Bi 02
Bi trc nghim v ngn ng Java cn bn ny s gip cc bn hiu thm c phn no v phng thc hot ng ca Java cng nh cch thc thi mt chng trnh ng dng c th trn ngn ng ny.

S cu: 10 im s cho mi cu: 1 nh du p n ng sai: ng: T l yu cu t: 75 %

-- Sai:

Thi gian lm bi: 10 Pht. Thi gian cn li: 00:00 1 - Cho mt component comp v mt container cont c kiu trnh by l BorderLayout. Cho bit cch gn comp vo v tr u ca cont. [a]--addTop(cont,comp) [b]--comp.add("North", cont) [c]--cont.addTop(comp) [d]--cont.add(comp,BorderLayout.NORTH) 2 - Cho mt component comp v mt container cont c kiu trnh by l FlowLayout. Cho bit cch gn comp vo cont. [a]--cont.add(comp) [b]--comp.add(cont) [c]--cont.addComponent(comp) [d]--cont.addAllComponents() 3 - Chn phng thc dng xc nh cch trnh by ca mt khung cha : [a]--startLayout() [b]--initLayout() [c]--layoutContainer() [d]--setLayout() 4 - Chn phng thc dng xc nh v tr v kch thc ca cc component [a]--setBounds() [b]--setSizeAndPosition() [c]--setComponentSize() [d]--setComponent() 5 - Chn kiu trnh by t cc component trn khung cha di dng bng. [a]--CardLayout [b]--BorderLayout [c]--GridLayout [d]--FlowLayout 6 - Chn phng thc dng gn ni dung cho Label : [a]--setLabel() [b]--setText() [c]--setTextLabel() [d]--setLabelText() 7 - Chn pht biu ng : [a]--TextComponent extends TextArea [b]--TextArea extends TextFieldc. [c]--TextField extends TextComponent [d]--TextComponent extends TextField 8 - Chn pht biu ng :

[a]--Lp CheckboxGroup dng nh ngha c RadioButtons [b]--Lp RadioGroup dng nh ngha c RadioButtons [c]--Tt c cc cu trn u ng [d]--Tt c cc cu trn u sai 9 - Chn cu lnh to ra TextArea c 10 dng v 20 ct : [a]--new TexArea(10,20) [b]--new TexArea(20,10) [c]--new TexArea(200) [d]--Tt c cc cu trn u sai 10 - Chn cu lnh to ra mt danh sch gm 5 mc chn v cho php thc hin chn nhiu mc cng lc : [a]--new List(true, 5) [b]--new List(5, true) [c]--new List(5, false) [d]--new List(false, 5)