Quiz2 Real
Quiz2 Real
Quiz2 Real
Name___________________________________
MULTIPLECHOICE.Choosetheonealternativethatbestcompletesthestatementoranswersthequestion.
1) CanyouusethesetBordermethodtosetaborderfor________?(chooseallthatapply)
A) Component
B) JLabel
C) JButton
D) Container
E) JComponent
1)
2) Analyzethefollowingcode:
2)
importjavax.swing.*;
publicclassTestextendsJFrame{
privateJButtonjbtOK=newJButton(OK);
publicstaticvoidmain(String[]args){
//Createaframeandsetitsproperties
JFrameframe=newTest();
frame.setTitle(LogicError);
frame.setSize(200,100);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
publicTest(){
jbtOK.setToolTipText(Thisisabutton);
add(newJButton(OK));
}
}
A) Thetooltiptextisdisplayedwhenyoumovethemouseonthebutton.
B) Thetooltiptextwillbedisplayedifyoureplaceadd(newJButton(OK))with
add(jbtOK).
C) Thetooltiptextwillbedisplayedifyoureplaceadd(newJButton(OK))withadd(jbtOK
=newJButton(OK)).
D) ThetooltiptextwillbedisplayedifyouswapthetwolinesintheTestconstructor.
3) Whichofthefollowingstatementsaretrue?(chooseallthatapply)
A) YoucansetabackgroundcoloronanyinstanceofComponent.
B) YoucansetaborderonanyinstanceofJComponent.
C) YoucansetaforegroundcoloronanyinstanceofComponent.
D) YoucansetatooltiptextonanyinstanceofJComponent.
3)
4) Youcanremoveacomponentfromacontainerbyusingtheremove()method.(Thisquestion
isnotcoveredinthetext)
A) true
B) false
4)
5) ToaddacomponentctoaJPanelp,use________.
A) p.getContentPane(c)
B) p.insert(c)
C) p.append(c)
D) p.add(c)
5)
6) WhatisbesttodescribetherelationshipbetweenComponentandFont?
A) Aggregation
B) Inheritance
C) Association
D) Composition
7) Whichofthefollowingclassesisaheavyweightcomponent?
A) JButton
B) JPanel
C) JFrame
D) JTextField
6)
7)
8) TheorderofthecomponentsaddedintoacontainerofFlowLayoutisimmaterial.
A) true
B) false
8)
9) Whichofthefollowingaresubclassesofjava.awt.Component?(chooseallthatapply)
A) Containerclasses
B) Layoutmanagers
C) HelperclassessuchasColorandFont
D) Swinguserinterfaceclasses
9)
10) Aframecanbeplacedinsideaframe.
A) true
10)
B) false
11) Themethod________setsthefont(Helvetica,20-pointbold)incomponentC.
A) c.setFont(newFont(helvetica,BOLD,20))
B) c.setFont(newFont(Helvetica,Font.bold,20))
C) c.setFont(Font(Helvetica,Font.BOLD,20))
D) c.setFont(newFont(Helvetica,Font.BOLD,20))
11)
12) Themethod________setsthebackgroundcolortoyellowinJFramef.
A) setBackground(Color.YELLOW)
B) setBackground(Color.yellow)
C) f.setBackground(Color.YELLOW)
D) f.setBackground(Color.yellow)
E) f.setBackGround(Color.yellow)
12)
13) Themethod________setstheforegroundcolortoyellowinJFramef.(chooseallthatapply)
A) f.setForeground(Color.yellow)
B) f.setForeGround(Color.yellow)
C) setForeground(Color.YELLOW)
D) f.setForeground(Color.YELLOW)
E) setForeground(Color.yellow)
13)
14) Theframetitlebarisinsidetheframe,soyoucannotdrawthingsintheareaofthetitlebar.
A) true
B) false
14)
15) YoushouldneverdirectlycallthepaintComponent()method.
A) true
B) false
15)
16) TheheaderforthepaintComponentmethodis________.
A) privatevoidpaintComponent(Graphicsg)
B) protectedvoidpaintComponent(Graphicsg)
C) publicvoidpaintComponent(Graphicsg)
D) protectedvoidpaintComponent()
16)
17) Thecoordinateoftheupper-leftcornerofaframeis________.
A) (10,10)
B) (100,100)
C) (25,25)
17)
D) (0,0)
18) The________pointofacomponenthascoordinate(0,0).
A) up-leftcorner
B) bottom-rightcorner
C) bottom-leftcorner
D) up-rightcorner
18)
19) Invoking________returnsthewidthofthestringinaFontMetricsobjectfm.
A) fm.stringWidth(s)
B) fm.getHeight(s)
C) fm.getWidth(s)
D) getLength(s)
19)
20) Therepaint()methodhasaparameterofGraphicstype.
A) true
B) false
20)
21) Youcandrawthingsonanapplet.
A) true
21)
B) false
22) YoucandrawgraphicsonanyGUIcomponents.
A) true
B) false
23) Youcandrawthingsonapanel.
A) true
B) false
22)
23)
24) Analyzethefollowingcode.
24)
importjava.awt.*;
importjavax.swing.*;
publicclassTest{
publicstaticvoidmain(String[]args){
JFrameframe=newJFrame(MyFrame);
frame.add(newMyDrawing(WelcometoJava!));
frame.setSize(300,300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setVisible(true);
}
}
classMyDrawingextendsJPanel{
Stringmessage;
publicMyDrawing(Stringmessage){
this.message=message;
}
publicvoidpaintcomponent(Graphicsg){
super.paintComponent(g);
g.drawString(message,20,20);
}
}
A) ItisaruntimetoinvokethesetVisible(true)twice.
B) Theprogramhasaruntimeerrorbecausethepaintcomponentshouldbespelledas
paintComponent.
C) TheprogramrunsfineanddisplaysWelcometoJava!
D) Theprogramhasasyntaxerrorbecausethepaintcomponentshouldbespelledas
paintComponent.
E) Theprogramruns,butitdoesnotdisplaythemessage.
25) Whichofthefollowingstatementsarecorrect?(chooseallthatapply)
A) Youcansetanimageonabutton,buttheimageisnotresizable.
B) Youcansetanimageonalabel,buttheimageisnotresizable.
C) YoucandrawanimageonaGUIcomponentusingthedrawImagemethodinthe
Graphicsobject.Thisimageisresizable.
25)
26) GivenaGraphicsobjectg,todrawancirclewithradius20centeredat(50,50),youuse
________.
A) g.drawOval(50,50,20,20)
B) g.drawOval(50,50,40,40)
C) g.drawOval(30,30,40,40)
D) g.drawOval(30,30,20,20)
26)
27) ThemethodintheActionEvent________returnstheactioncommandofthebutton.
A) getID()
B) paramString()
C) getModifiers()
D) getActionCommand()
27)
28) Whichofthefollowingstatementsaretrue?(chooseallthatapply)
A) AlltheeventclassesaresubclassesofEventObject.
B) Ifacomponentcangenerateanevent,anysubclassofthecomponentcangeneratethe
sametypeofevent.
C) EveryGUIcomponentcangenerateMouseEvent,KeyEvent,FocusEvent,and
ComponentEvent.
D) Acomponentonwhichaneventisgeneratediscalledthesourceobject.
28)
29) Thelisteners________methodisinvokedafteramousebuttonisreleased.(chooseallthat
apply)
A) publicvoidmouseExited(MouseEvente)
B) publicvoidmousePressed(MouseEvente)
C) publicvoidmouseEntered(MouseEvente)
D) publicvoidmouseClicked(MouseEvente)
E) publicvoidmouseReleased(MouseEvente)
29)
30) Whichofthefollowingstatementsaretrue?(chooseallthatapply)
A) YoucanusetheaddActionListenermethodintheTimerclasstoaddalistener.
B) YoucanaddalistenerintheTimerconstructor.
C) YoucanspecifyadelayusingthesetDelaymethod;.
D) YoucanspecifyadelayintheTimerconstructor.
30)
31) Theinterface________shouldbeimplementedtolistenforabuttonactionevent.
A) ActionListener
B) MouseListener
C) WindowListener
D) ContainerListener
E) FocusListener
31)
32) Asourceobjectcanregisteronlyonelistener.
A) true
32)
B) false
33) TocheckwhetheraDELETEkeyispressedorreleased,whichhandlershouldbeused?
(chooseallthatapply)
A) keyReleased(KeyEvente)
B) keyTyped(KeyEvente)
C) keyPressed(KeyEvente)
33)
34) Tolistentomousemovedevents,thelistenermustimplementthe________interfaceorextend
the________class.
A) MouseListener/MouseAdapter
B) WindowListener/WindowAdapter
C) ComponentListener/ComponentAdapter
D) MouseMotionListener/MouseMotionAdapter
34)
35) Whichofthefollowingstatementsaretrue?(chooseallthatapply)
A) YoucanaddmultiplelistenersforaTimerobject.
B) YoumustalwaysspecifyalistenerwhencreatingaTimerobject.
C) Tostartatimer,invoketimer.start().
D) Whenatimeriscreated,itisautomaticallystarted.
E) Tostopatimer,invoketimer.stop().
35)
36) Whichofthefollowingstatementsaretrue?(chooseallthatapply)
A) Ananonymousinnerclassisaninnerclasswithoutaname.
B) AnanonymousinnerclassiscompiledintoaclassnamedOuterClassName$n.class.
C) Ananonymousinnerclassmustalwaysextendasuperclassorimplementaninterface,
butitcannothaveanexplicitextendsorimplementsclause.
D) Ananonymousinnerclassmustimplementalltheabstractmethodsinthesuperclassor
intheinterface.
E) Ananonymousinnerclassalwaysusestheno-argconstructorfromitssuperclassto
createaninstance.Ifananonymousinnerclassimplementsaninterface,theconstructoris
Object().
36)
37) ________isacomponentthatenablestheusertochooseasinglevalueormultiplevalues.
A) Alist
B) Acombobox
C) Atextfield
D) Alabel
37)
38) Youcanseeseveralframesatonetime.
A) true
38)
B) false
39) ThefollowingarepropertiesofaJSlider.(chooseallthatapply)
A) visibleAmount
B) maximum
C) minimum
39)
D) orientation
40) Themethod________specifiesthatthetextandiconarehorizontallyalignedtotherightinthe
labeljlbl.
A) jlbl.setHorizontalAlignment(JButton.RIGHT)
B) jlbl.setVerticalTextPosition(JButton.LEFT)
C) jlbl.setHorizontalTextPosition(JButton.RIGHT)
D) jlbl.setHorizontalAlignment(JButton.LEFT)
E) jlbl.setHorizontalTextPosition(JButton.LEFT)
40)
41) ThefollowingarepropertiesofaJScrollBar.(chooseallthatapply)
A) maximum
B) visibleAmount
C) orientation
41)
D) minimum
42) ________maygenerateActionEvent.(chooseallthatapply)
A) JTextArea
B) JTextField
C) JComboBox
D) JList
42)
43) Themethod________specifiesthatthetextisplacedontherightoftheiconinthebuttonjbt.
A) jbt.setHorizontalTextPosition(JButton.RIGHT)
B) jbt.setHorizontalTextPosition(JButton.LEFT)
C) jbt.setHorizontalAlignment(JButton.RIGHT)
D) jbt.setHorizontalAlignment(JButton.LEFT)
E) jbt.setVerticalTextPosition(JButton.LEFT)
43)
44) Whichofthefollowingistrue?(chooseallthatapply)
A) AllthemethodsintheJButtonclassareinheritedfromthejavax.swing.AbstractButton
class.
B) YoucancreateaJButtonbyspecifyinganicon.
C) YoucancreateaJButtonbyatext.
D) YoucancreateaJButtonusingitsdefaultconstructor.
E) YoucancreateaJButtonbyspecifyinganiconandtext.
44)
45) ________returnstheselecteditemonaJComboBoxjcbo.
A) jcbo.getSelectedIndex()
B) jcbo.getSelectedIndices()
C) jcbo.getSelectedItems()
D) jcbo.getSelectedItem()
45)
46) Anynumberdividedby0wouldgenerateanexception.
A) true
B) false
46)
47) Whichoftheclassesareinthejava.langpackage?(chooseallthatapply)
A) IOException
B) Exception
C) Throwable
D) RuntimeException
47)
48) Aninstanceof________areuncheckedexceptions.(chooseallthatapply)
A) NumberFormatException
B) Error
C) RuntimeException
D) Throwable
E) Exception
48)
49) Analyzethefollowingprogram.
49)
classTest{
publicstaticvoidmain(String[]args){
try{
Strings=5.6;
Integer.parseInt(s);//CauseaNumberFormatException
inti=0;
inty=2/i;
System.out.println(WelcometoJava);
}
catch(Exceptionex){
System.out.println(ex);
}
}
}
A) AnexceptionisraisedduetoInteger.parseInt(s);
B) Theprogramhasacompilationerror.
C) Theprogramcompilesandrunswithoutexceptions.
D) Anexceptionisraiseddueto2/i;
50) Whichofthefollowingstatementiscorrecttorethrowexceptionexalongwithnew
information?
A) throwex;thrownewException(Somenewinfo);
B) thrownewException(Newinfo,ex);
C) thrownewException(Newinfo);throwex;
D) thrownewException(ex,Newinfo);
50)
51) Aninstanceof________describessystemerrors.Ifthistypeoferroroccurs,thereislittleyou
candobeyondnotifyingtheuserandtryingtoterminatetheprogramgracefully.
A) Error
B) NumberFormatException
C) Throwable.
D) RuntimeException
E) Exception
51)
52) Anynumberdividedby0wouldcauseacompilationerror.
A) true
B) false
52)
53) Analyzethefollowingcode.
53)
importjava.util.*;
publicclassTest{
publicstaticvoidmain(String[]args)throwsException{
TreeSetset=newTreeSet();
set.add(Red);
set.add(Yellow);
set.add(Green);
set.add(Blue);
SortedSettemp=set.tailSet(Purple);
System.out.println(temp.first());
}
}
A) TheprogramdisplaysGreen
B) TheprogramdisplaysRed
C) TheprogramdisplaysPurple
D) TheprogramdisplaysBlue
E) TheprogramdisplaysYellow
54) WhenyoucreateanArrayListusingArrayList<String> x= newArrayList<String>(2),
________.(chooseallthatapply)
A) twoelementsarecreatedinthearraylist
B) thearraylistsizeiscurrently2
C) thearraylistcapacityiscurrently2
D) noelementsarecurrentlyinthearraylist
54)
55) Analyzethefollowingcode:
55)
importjava.util.*;
publicclassTest{
publicstaticvoidmain(String[]args){
PriorityQueue<Integer>queue=
newPriorityQueue<Integer>(
Arrays.asList(60,10,50,30,40,20));
while(!queue.isEmpty())
System.out.print(queue.poll()+);
}
}
A) Theprogramdisplays601050304020
B) Theprogramdisplays102030405060
C) Thereisnoguaranteethattheprogramdisplays102030405060
D) Theprogramdisplays605040302010
56) Whichofthefollowingaretrue?(chooseallthatapply)
A) Youcaninsertanelementanywhereisanarraylist.
B) Youshoulduseanarraylistifyourapplicationdoesnotrequireaddingandremovean
elementanywhereinalist.
C) Youcanusealinkedlisttoimproveefficiencyforaddingandremoveanelement
anywhereinalist.
D) Youcaninsertanelementanywhereisalinkedlist.
56)
57) Whichofthefollowingstatementsaretrue?(chooseallthatapply)
A) TheAbstractListclassprovidesapartialimplementationfortheListinterface.
B) java.util.Listinheritsallthemethodsfromjava.util.Collection.Additionally,itcontains
newmethodsformanipulatingalist.
C) LinkedListisaconcreteimplementationofListusingalinkedlist.LinkedListcontainsall
themethodsinListandadditionalnewmethodsformanipulatingalinkedlist.
D) ArrayListisaconcreteimplementationofListusinganarray.
E) ListIteratorisasubinterfaceofIteratoranditprovidesthemethodstosupport
bi-directionaltraversalofalist.
57)
58) WhichofthefollowingmethodsareintheCollectioninterface?(chooseallthatapply)
A) getSize()
B) size()
C) clear()
D) isEmpty()
58)
59) IfapreparedstatementpreparedStatementisaSQLSELECTstatement,youexecutethe
statementusing________.
A) preparedStatement.executeQuery();
B) preparedStatement.executeUpdate();
C) preparedStatement.execute();
D) preparedStatement.query();
59)
60) Inarelationaldatamodel,________providesthemeansforaccessingandmanipulatingdata.
(chooseallthatapply)
A) Structure
B) Language
C) Integrity
D) SQL
60)
61) Supposeapreparedstatementiscreatedasfollows:
61)
StatementpreparedStatement=connection.prepareStatement
(insertintoStudent(firstName,mi,lastName)+
values(?,?,?));
TosetavalueJohntothefirstparameter,use
A) preparedStatement.setString(1,John);
C) preparedStatement.setString(1,John);
B) preparedStatement.setString(0,John);
D) preparedStatement.setString(0,John);
62) Whichofthefollowingstatementsaretrue?(chooseallthatapply)
A) CallableStatementisforexecutingpredefinedfunctionsandprocedures.
B) CallableStatementismoreefficientthanPreparedStatement.
C) CallableStatementisforSQLquerystatementsonly.Youcannotcreatea
CallableStatementforSQLupdatestatements.
D) CallableStatementisasubinterfaceofPreparedStatement.
62)
63) Whereiscom.mysql.jdbc.Driverlocated?
A) inaJARfileclasses12.jardownloadablefromthebooksCompanionWebsite
B) inaJARfileojdbc14.jardownloadablefromthebooksCompanionWebsite
C) inaJARfilemysqljdbc.jardownloadablefromthebooksCompanionWebsite
D) inthestandardJavalibrarybundledwithJDK
63)
64) Databasemetadataareretrievedthrough________.
A) aConnectionobject
B) aResultSetObject
C) aStatementobject
D) aPreparedStatementobject
64)
65) Youcanusemethods________onanyinstanceofjava.awt.Component.(chooseallthatapply)
A) setBackground
B) setBorder
C) getBackground
D) getHeight
E) getWidth
65)
66) SupposeaJFrameusestheGridLayout(2,2).Ifyouaddsixbuttonstotheframe,howmany
columnsaredisplayed?
A) 1
B) 3
C) 2
D) 4
66)
67) CanyouusethesetToolTipmethodtosetatooltipfor________?(chooseallthatapply)
A) JLabel
B) JComponent
C) Component
D) Container
E) JButton
67)
68) Whatisbesttodescribetherelationshipbetweenacontainerandalayoutmanager?
A) Aggregation
B) Association
C) Composition
D) Inheritance
68)
10
69) Abuttonsbackgroundcolorcanbechanged,aswellasitsforegroundcolor.
A) true
B) false
69)
70) GivenaGraphicsobjectg,todrawanoutlineofarectangleofwidth20andheight50withthe
upper-leftcornerat(20,20),youuse________.
A) g.drawRectFill(20,20,20,50)
B) g.drawRectFill(20,50,20,20)
C) g.drawRect(20,20,20,50)
D) g.drawRect(20,50,20,20)
70)
71) GivenaGraphicsobjectg,todrawafilledovalwithwidth20andheight30centeredat(50,
50),youuse________.
A) g.fillOval(40,35,20,30)
B) g.fillOval(30,30,20,30)
C) g.fillOval(50,50,20,30)
D) g.fillOval(30,30,40,30)
E) g.fillOval(50,50,40,30)
71)
72) Youshouldoverridethe________methodtodrawthingsonaSwingcomponent.
A) init()
B) paintComponent()
C) repaint()
D) update()
72)
73) Youshouldneverdirectlycalltherepaint()method.
A) true
B) false
73)
74) Whichofthefollowingstatementsaretrue?(chooseallthatapply)
A) Thelistenerobjectsclassmustimplementthecorrespondingevent-listenerinterface.
B) Asourcemayhavemultiplelisteners.
C) Eacheventclasshasacorrespondinglistenerinterface.
D) Thelistenerobjectmustberegisteredbythesourceobject.
E) Alistenermaylistenformultiplesources.
74)
75) TobealistenerforActionEvent,anobjectmustbeaninstanceof________.
A) ActionListener
B) EventObject
C) ActionEvent
D) WindowListener
E) WindowEvent
75)
76) Toenableacomponenttolistentokeyboardevents,youneedto________.
A) ImplementtheKeyListenerinterfaceforthecomponent
B) InvokethecomponentsrequestFocusmethodtosetfocusonthiscomponent
C) OverridetheisFocusTraversablemethoddefinedintheComponentclasstoreturntrue
D) Alloftheabove.
76)
77) Whichofthefollowingstatementsaretrue?(chooseallthatapply)
A) AllthemethodsinJCheckBoxarealsoinJButton.
B) YoucanuseanicononJCheckBox.
C) AllthemethodsinJCheckBoxareinheritedfromjavax.swing.AbstractButton.
D) JButtonandJCheckBoxfiresametypesofevents.
77)
11
78) Whichofthefollowingstatementsaretrue?(chooseallthatapply)
A) Youcanspecifythenumberofcolumnsinatextarea.
B) Youcanspecifyahorizontaltextalignmentinatextarea.
C) Youcandisableeditingonatextarea.
D) Youcancreateatextfieldwithaspecifiedtextarea.
78)
79) Youcanchangethecaptionofalabel.
A) true
79)
B) false
80) Whatisdisplayedontheconsolewhenrunningthefollowingprogram?
classTest{
publicstaticvoidmain(String[]args){
try{
System.out.println(WelcometoJava);
return;
}
finally{
System.out.println(Thefinallyclauseisexecuted);
}
}
}
A) Thefinallyclauseisexecuted
B) WelcometoJavafollowedbyThefinallyclauseisexecutedinthenextline
C) WelcometoJava
D) Noneoftheabove
12
80)
81) Whatisdisplayedontheconsolewhenrunningthefollowingprogram?
81)
classTest{
publicstaticvoidmain(String[]args){
try{
System.out.println(WelcometoJava);
inti=0;
inty=2/i;
System.out.println(WelcometoJava);
}
finally{
System.out.println(Endoftheblock);
}
System.out.println(Endoftheblock);
}
}
A) TheprogramdisplaysWelcometoJavatwotimesfollowedbyEndoftheblock.
B) TheprogramdisplaysWelcometoJavaandEndoftheblock,andthenterminates
becauseofanunhandledexception.
C) TheprogramdisplaysWelcometoJavathreetimesfollowedbyEndoftheblock.
D) TheprogramdisplaysWelcometoJavatwotimesfollowedbyEndoftheblocktwo
times.
82) Whatexceptiontypedoesthefollowingprogramthrow?
82)
publicclassTest{
publicstaticvoidmain(String[]args){
Objecto=newObject();
Stringd=(String)o;
}
}
A) ArrayIndexOutOfBoundsException
B) ArithmeticException
C) StringIndexOutOfBoundsException
D) Noexception
E) ClassCastException
83) Whichofthefollowingiscorrecttoperformthesetintersectionoftwosetss1ands2?
A) s1.intersect(s2)
B) s1.retainAll(s2)
C) s1.intersection(s2)
D) s1.join(s2)
83)
84) Whichmethoddoyouusetoremoveanelementfromasetorlistnamedx?
A) x.delete(element)
B) x.deletes(element)
C) x.remove(element)
D) x.removes(element)
E) Noneoftheabove
84)
13
85) AdatabaseURLforaMySQLdatabasenamedtestonhostpanda.armstrong.eduis________.
A) jdbc:mysql:/panda.armstrong.edu/test
B) jdbc:mysql://panda.armstrong.edu/test
C) jdbc.mysql://panda.armstrong.edu/test
D) jdbc.mysql.//panda.armstrong.edu/test
85)
86) Whichofthefollowingstatementsaretrue?(chooseallthatapply)
A) Youmaycreatemultiplestatementsfromoneconnection.
B) Youmaycreatemultipleconnectionstoadatabase.
C) YoucansendqueriesandupdatestatementsthroughaStatementobject.
D) YoumayloadmultipleJDBCdriversinaprogram.
86)
87) Analyzethefollowingcode.
87)
importjava.awt.*;
importjavax.swing.*;
publicclassTest{
publicstaticvoidmain(String[]args){
Componentc=newJButton(OK);
JFrameframe=newJFrame(MyFrame);
frame.add(c);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
A) YoucannotcreateaJFrameusingnewJFrame(MyFrame).
B) YoucannotassignaJButtontoavariableofjava.awt.Component.
C) YoucannotaddaSwingcomponentdirectlytoaJFrameusingadd(c)priortoJDK1.4,
butitisOKinJDK1.5.
D) YoucanonlyaddctoacontainerbecausecstypeisComponent.
88) Whichofthefollowingstatementsaretrue?(chooseallthatapply)
A) Auserinterfaceobjectsuchas(button,list)canappearinonecontainer.
B) EveryinstanceofComponentcanbeaddedtoacontainer.
C) AllSwingGUIcomponentsarelightweight.
D) TodistinguishnewSwingcomponentclassesfromtheirAWTcounterparts,SwingGUI
componentclassesarenamedwithaprefixJ.
E) AcontainersuchasJFrameisalsoacomponent.
14
88)
89) Analyzethefollowingcode.
89)
importjava.awt.*;
importjavax.swing.*;
publicclassTestextendsJFrame{
publicTest(){
add(newMyDrawing(WelcometoJava!));
}
publicstaticvoidmain(String[]args){
JFrameframe=newJFrame();
frame.setSize(300,300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
classMyDrawingextendsJPanel{
Stringmessage;
publicMyDrawing(Stringmessage){
this.message=message;
}
publicvoidpaintComponent(Graphicsg){
super.paintComponent(g);
g.drawString(message,20,20);
}
}
A) TheprogramwoulddisplayWelcometoJava!ifnewJFrame()isreplacedbynew
Test(MyFrame).
B) TheprogramrunsfineanddisplaysWelcometoJava!
C) TheprogramwoulddisplayWelcometoJava!ifnewJFrame()isreplacedbynewTest().
D) TheprogramwoulddisplayWelcometoJava!ifnewJFrame()isreplacedbyTest().
90) Whichofthefollowingstatementsaretrue?(chooseallthatapply)
A) ThekeyReleasedhandlerisinvokedwhenakeyisreleased.
B) ThekeyTypedhandlerisinvokedwhenaUnicodecharacterisentered.
C) ThekeyPressedhandlerisinvokedwhenakeyispressed.
D) ThekeyTypedhandlerisinvokedwhenakeyisentered.
90)
91) Whichofthefollowingstatementsaretrue?(chooseallthatapply)
A) Youcancreatealabelwithbothtextandicon.
B) AllthemethodsinJLabelareinheritedfromjavax.swing.AbstractButton.
C) Youcancreatealabelwithanicon.
D) YoucansetamnemonickeyinaJLabel.
91)
15
92) Whatiswronginthefollowingprogram?
92)
classTest{
publicstaticvoidmain(String[]args){
try{
System.out.println(WelcometoJava);
}
}
}
A) Youcannothaveatryblockwithoutacatchblock.
B) Amethodcallthatdoesnotdeclareexceptionscannotbeplacedinsideatryblock.
C) Nothingiswrong.
D) Youcannothaveatryblockwithoutacatchblockorafinallyblock.
93) Whichofthefollowingstatementsaretrue?(chooseallthatapply)
A) AllinterfacesandclassesintheCollectionsframeworkaredeclaredusinggenerictypein
JDK1.5.
B) TheCollectioninterfaceprovidesthebasicoperationsforaddingandremovingelements
inacollection.
C) SomeofthemethodsintheCollectioninterfacecannotbeimplementedintheconcrete
subclass.Inthiscase,themethodwouldthrow
java.lang.UnsupportedOperationException,asubclassofRuntimeException.
D) TheAbstractCollectionclassisaconvenienceclassthatprovidespartialimplementation
fortheCollectioninterface.
E) TheCollectioninterfaceistherootinterfaceformanipulatingacollectionofobjects.
93)
94) Inarelationaldatamodel,________definestherepresentationofthedata.
A) Structure
B) SQL
C) Language
D) Integrity
94)
95) Apanelcanbeplacedinsideaframe.
A) true
95)
B) false
96) Whichofthefollowingmethodsdrawsafilled3Drectangle.(chooseallthatapply)
A) g.fill3DRect(50,50,20,30,true)
B) g.fill3DRect(50,50,20,30,1)
C) g.fill3DRect(50,50,20,30,false)
D) g.fill3DRect(50,50,20,30)
96)
97) Thelistenerforanactioneventisaninstanceof________.
A) ItemListener
B) KeyListener
C) MouseListener
D) ComponentListener
E) ActionListener
97)
98) HowmanyitemscanbeselectedfromaJComboBoxobjectatatime?
A) 2
B) 0
C) 1
16
98)
D) Unlimited
99) Whatexceptiontypedoesthefollowingprogramthrow?
99)
publicclassTest{
publicstaticvoidmain(String[]args){
System.out.println(1/0);
}
}
A) ArrayIndexOutOfBoundsException
B) StringIndexOutOfBoundsException
C) ArithmeticException
D) ClassCastException
E) Noexception
100) Whichofthefollowingstatementsaretrue?(chooseallthatapply)
A) YoucanreducethecapacityofaLinkedListbyinvokingthetrimToSize()methodonthe
list.
B) AnArrayListcanshrinkautomatically.
C) AnArrayListcangrowautomatically.
D) YoucanreducethecapacityofanArrayListbyinvokingthetrimToSize()methodonthe
list.
17
100)
AnswerKey
Testname:QUIZ2_REAL
1) B,C,E
2) B
3) A,B,C,D
4) A
5) D
6) C
7) C
8) B
9) A,D
10) B
11) D
12) A
13) A,D
14) A
15) A
16) B
17) D
18) A
19) A
20) B
21) A
22) A
23) A
24) E
25) A,B,C
26) C
27) D
28) A,B,C,D
29) D,E
30) A,B,C,D
31) A
32) B
33) A,C
34) D
35) A,B,C,E
36) A,B,C,D,E
37) A
38) A
39) B,C,D
40) A
41) A,B,C,D
42) B,C
43) A
44) A,B,C,D,E
45) D
46) B
47) B,C,D
48) A,B,C
18
AnswerKey
Testname:QUIZ2_REAL
49)
50)
51)
52)
53)
54)
55)
56)
57)
58)
59)
60)
61)
62)
63)
64)
65)
66)
67)
68)
69)
70)
71)
72)
73)
74)
75)
76)
77)
78)
79)
80)
81)
82)
83)
84)
85)
86)
87)
88)
89)
90)
91)
92)
93)
94)
95)
96)
A
B
A
B
B
C,D
B
A,B,C,D
A,B,C,D,E
B,C,D
A
B,D
A
A,D
C
A
A,C,D,E
B
A,B,E
A
A
C
A
B
B
A,B,C,D,E
A
D
A,B,C
A,C,D
A
B
B
E
B
C
B
A,B,C,D
C
A,D,E
C
A,B,C
A,C
D
A,B,C,D,E
A
A
A,C
19
AnswerKey
Testname:QUIZ2_REAL
97) E
98) C
99) C
100) C,D
20