Java MCQ Document

download Java MCQ Document

of 45

Transcript of Java MCQ Document

  • 8/13/2019 Java MCQ Document

    1/45

    1.The Java interpreter is used for the execution of the source code.TrueFalseAns: a.2) On successful compilation a file with the class extension is created.a) True

    b) FalseAns: a.) The Java source code can be created in a !otepad editor.a) Trueb) FalseAns: a.") The Java #ro$ram is enclosed in a class definition.a) Trueb) FalseAns: a.%) &hat declarations are re'uired for ever( Java applicationAns: A class and the main* ) method declarations.+) &hat are the two parts in executin$ a Java pro$ram and their purposesAns: Two parts in executin$ a Java pro$ram are:Java ,ompiler and Java -nterpreter.The Java ,ompiler is used for compilation and the Java -nterpreter is used for execution of theapplication.) &hat are the three OO#s principles and define themAns : /ncapsulation0 -nheritance and #ol(morphism are the three OO#s#rinciples./ncapsulation:-s the echanism that binds to$ether code and the data it manipulates0 and eeps both safefrom outside interference and misuse.-nheritance:-s the process b( which one ob3ect ac'uires the properties of another ob3ect.#ol(morphism:-s a feature that allows one interface to be used for a $eneral class of actions.

    4) &hat is a compilation unitAns : Java source code file.5) &hat output is displa(ed as the result of executin$ the followin$ statement6(stem.out.println*788 9oos lie a comment.7)88 9oos lie a commentThe statement results in a compilation error9oos lie a comment!o output is displa(edAns : a.1;) -n order for a source code file0 containin$ the public class Test0 to successfull( compile0which of the followin$ must be true

    -t must have a paca$e statement-t must be named Test.3ava-t must import 3ava.lan$-t must declare a public class named TestAns : b11) &hat are identifiers and what is namin$ conventionAns : -dentifiers are used for class names0 method names and variable names. An identifier ma(be an( descriptive se'uence of upper case < lower case letters0numbers or underscore ordollar si$n and must not be$in with numbers.

  • 8/13/2019 Java MCQ Document

    2/45

    12) &hat is the return t(pe of pro$ram=s main* ) methodAns : void1) &hat is the ar$ument t(pe of pro$ram=s main* ) methodAns : strin$ arra(.1") &hich characters are as first characters of an identifierAns : A > ?0 a > @0 0B

    1%) &hat are different commentsAns : 1) 88 CC sin$le line comment2) 8D CCD8 multiple line comment) 8DD CCD8 documentation1+) &hat is the difference between constructor method and methodAns : ,onstructor will be automaticall( invoed when an ob3ect is created. &hereas methodhas to be call explicitl(.1) &hat is the use of bin and lib in JEAns : Gin contains all tools such as 3avac0 applet viewer0 awt tool etc.0 whereas 9ibcontains all paca$es and variables.

    Eata t(pes0variables and Arra(s1) &hat is meant b( variableAns: Hariables are locations in memor( that can hold values. Gefore assi$nin$ an( value to avariable0 it must be declared.2) &hat are the inds of variables in Java &hat are their usesAns: Java has three inds of variables namel(0 the instance variable0 the local variable and theclass variable.9ocal variables are used inside blocs as counters or in methods as temporar( variables and areused to store information needed b( a sin$le method.-nstance variables are used to define attributes or the state of a particular ob3ect and are usedto store information needed b( multiple methods in the ob3ects.,lass variables are $lobal to a class and to all the instances of the class and are useful forcommunicatin$ between different ob3ects of all the same class or eepin$ trac of $lobal

    states.) Iow are the variables declaredAns: Hariables can be declared an(where in the method definition and can be initiali@ed durin$their declaration.The( are commonl( declared before usa$e at the be$innin$ of the definition.Hariables with the same data t(pe can be declared to$ether. 9ocal variables must be $iven avalue before usa$e.") &hat are variable t(pesAns: Hariable t(pes can be an( data t(pe that 3ava supports0 which includes the ei$ht primitivedata t(pes0 the name of a class or interface and an arra(.%) Iow do (ou assi$n values to variablesAns: Halues are assi$ned to variables usin$ the assi$nment operator .+) &hat is a literal Iow man( t(pes of literals are thereAns: A literal represents a value of a certain t(pe where the t(pe describes how that value

    behaves.There are different t(pes of literals namel( number literals0 character literals0boolean literals0 strin$ literals0etc.) &hat is an arra(Ans: An arra( is an ob3ect that stores a list of items.4) Iow do (ou declare an arra(Ans: Arra( variable indicates the t(pe of ob3ect that the arra( holds./x: int arrKL5) Java supports multidimensional arra(s.

  • 8/13/2019 Java MCQ Document

    3/45

    a)Trueb)FalseAns: a.1;) An arra( of arra(s can be created.a)Trueb)False

    Ans: a.11) &hat is a strin$Ans: A combination of characters is called as strin$.12) 6trin$s are instances of the class 6trin$.a)Trueb)FalseAns: a.1) &hen a strin$ literal is used in the pro$ram0 Java automaticall( creates instances of thestrin$ class.a)Trueb)FalseAns: a.1") &hich operator is to create and concatenate strin$Ans: Addition operator*M).1%) &hich of the followin$ declare an arra( of strin$ ob3ects6trin$K L s6trin$ K Ls:6trin$K sL:6trin$ sK L:Ans : a0 b and d1+) &hat is the value of aKL as the result of the followin$ arra( declaration12"Ans : d1) &hich of the followin$ are primitive t(pes

    b(te6trin$inte$erFloatAns : a.14) &hat is the ran$e of the char t(pe; to 21+; to 21%; to 21+C1; to 21%C1Ans. d15) &hat are primitive data t(pesAns : b(te0 short0 int0 lon$

    float0 doublebooleanchar2;) &hat are default values of different primitive t(pesAns : int C ;short C ;b(te C ;lon$ C ; lfloat C ;.; f

  • 8/13/2019 Java MCQ Document

    4/45

    double C ;.; dboolean C falsechar C null21) ,onvertin$ of primitive t(pes to ob3ects can be explicitl(.a)Trueb)False

    Ans: b.22) Iow do we chan$e the values of the elements of the arra(Ans : The arra( subscript expression can be used to chan$e the values of the elements of thearra(.2) &hat is final varaibleAns : -f a variable is declared as final variable0 then (ou can not chan$e its value. -t becomesconstant.2") &hat is static variableAns : 6tatic variables are shared b( all instances of a class.

    Operators1) &hat are operators and what are the various t(pes of operators available in JavaAns: Operators are special s(mbols used in expressions.The followin$ are the t(pes of operators:Arithmetic operators0Assi$nment operators0-ncrement < Eecrement operators09o$ical operators0Giwise operators0,omparison8Nelational operators and,onditional operators2) The MM operator is used for incrementin$ and the CC operator is used fordecrementin$.a)Trueb)False

    Ans: a.) ,omparison89o$ical operators are used for testin$ and ma$nitude.a)Trueb)FalseAns: a.") ,haracter literals are stored as unicode characters.a)Trueb)FalseAns: a.%) &hat are the 9o$ical operatorsAns: ON*)0 A!E*

  • 8/13/2019 Java MCQ Document

    5/45

    5) ,an a double value be cast to a b(teAns : Ses1;) ,an a b(te ob3ect be cast to a double value Ans : !o. An ob3ect cannot be cast to a primitive value.11) &hat are order of precedence and associativit(Ans : Order of precedence the order in which operators are evaluated in expressions.

    Associativit( determines whether an expression is evaluated leftCri$ht or ri$htCleft.12) &hich Java operator is ri$ht associativit(Ans : operator.1) &hat is the difference between prefix and postfix of CC and MM operatorsAns : The prefix form returns the increment or decrement operation and returns the value ofthe increment or decrement operation.The postfix form returns the current value of all of the expression and thenperforms the increment or decrement operation on that value.1") &hat is the result of expression %."% M 7027The double value 4.+The strin$ 774.+7The lon$ value 4.The 6trin$ 7%."%.27Ans : d1%) &hat are the values of x and ( x % ( MMxAns : x + ( +1+) &hat are the values of x and @x % @ xMMAns : x + @ %

    ,ontrol 6tatements

    1) &hat are the pro$rammin$ constructsAns: a) 6e'uentialb) 6election CC if and switch statementsc) -teration CC for loop0 while loop and doCwhile loop2) class conditional public static void main*6trin$ ar$sKL) int i 2;int 3 %%int @ ;@ i U 3 i : 3 88 ternar( operator6(stem.out.println*7The value assi$ned is 7 M @)VV

    &hat is output of the above pro$ramAns: The value assi$ned is 2;) The switch statement does not re'uire a brea.a)Trueb)FalseAns: b.") The conditional operator is otherwise nown as the ternar( operator.a)Trueb)False

  • 8/13/2019 Java MCQ Document

    6/45

    Ans: a.%) The while loop repeats a set of code while the condition is false.a)Trueb)FalseAns: b.+) The doCwhile loop repeats a set of code atleast once before the condition is tested.

    a)Trueb)FalseAns: a.) &hat are difference between brea and continueAns: The brea e(word halts the execution of the current loop and forces control out of theloop.The continue is similar to brea0 except that instead of haltin$ the execution of the loop0 itstarts the next iteration.

    4) The for loop repeats a set of statements a certain number of times until a condition ismatched.a)Trueb)FalseAns: a.5) ,an a for statement loop indefintel(Ans : Ses.1;) &hat is the difference between while statement and a do statement8Ans : A while statement checs at the be$innin$ of a loop to see whether the next loopiteration should occur.A do statement checs at the end of a loop to see whether the next iteration of a loop shouldoccur. The do statement will alwa(s execute the bod( of a loop at least once.

    -ntroduction to ,lasses and ethods1) &hich is used to $et the value of the instance variablesAns: Eot notation.2) The new operator creates a sin$le instance named class and returns a

    reference to that ob3ect.a)Trueb)FalseAns: a.) A class is a template for multiple ob3ects with similar features.a)Trueb)FalseAns: a.") &hat is mean b( $arba$e collectionAns: &hen an ob3ect is no lon$er referred to b( an( variable0 Java automaticall(reclaims memor( used b( that ob3ect. This is nown as $arba$e collection.%) &hat are methods and how are the( definedAns: ethods are functions that operate on instances of classes in which the( are

    defined.Ob3ects can communicate with each other usin$ methods and can call methods inother classes.ethod definition has four parts. The( are name of the method0 t(pe of ob3ect or primitivet(pe the method returns0 a list of parameters and the bod( of the method.A methodWs si$nature is a combination of the first three parts mentioned above.+) &hat is callin$ methodAns: ,allin$ methods are similar to callin$ or referrin$ to an instance variable. These methodsare accessed usin$ dot notation./x: ob3.methodname*param10param2)

  • 8/13/2019 Java MCQ Document

    7/45

    ) &hich method is used to determine the class of an ob3ectAns: $et,lass* ) method can be used to find out what class the belon$s to. This class is definedin the ob3ect class and is available to all ob3ects.4) All the classes in 3ava.lan$ paca$e are automaticall( imported whena pro$ram is compiled.a)True

    b)FalseAns: a.5) Iow can class be imported to a pro$ramAns: To import a class0 the import e(word should be used as shown.import classname1;) Iow can class be imported from a paca$e to a pro$ramAns: import 3ava . paca$ename . classname *or) import 3ava.paca$e name.D11) &hat is a constructorAns: A constructor is a special ind of method that determines how an ob3ect isinitiali@ed when created.12) &hich e(word is used to create an instance of a classAns: new.1) &hich method is used to $arba$e collect an ob3ectAns: finali@e *).1") ,onstructors can be overloaded lie re$ular methods.a)Trueb)FalseAns: a.1%) &hat is castin$Ans: ,astin$ is bused to convert the value of one t(pe to another.

    1+) ,astin$ between primitive t(pes allows conversion of one primitive t(pe to another.a)Trueb)FalseAns: a.

    1) ,astin$ occurs commonl( between numeric t(pes.a)Trueb)FalseAns: a.14) Goolean values can be cast into an( other primitive t(pe.a)Trueb)FalseAns: b.15) ,astin$ does not affect the ori$inal ob3ect or value.a)Trueb)FalseAns: a.2;) &hich cast must be used to convert a lar$er value into a smaller one

    Ans: /xplicit cast.21) &hich cast must be used to cast an ob3ect to another classAns: 6pecific cast.22) &hich of the followin$ features are common to both Java < ,MMA.The class declarationb.The access modifiersc.The encapsulation of data < methods with in ob3ectsd.The use of pointersAns: a0b0c.

  • 8/13/2019 Java MCQ Document

    8/45

    2) &hich of the followin$ statements accuratel( describe the use of access modifiers within aclass definitiona.The( can be applied to both data < methodsb.The( must precede a classWs data variables or methodsc.The( can follow a classWs data variables or methodsd.The( can appear in an( order

    e.The( must be applied to data variables first and then to methodsAns: a0b0d.2") 6uppose a $iven instance variable has been declared private.,an this instance variable be manipulated b( methods out side its classa.(esb.noAns: b.2%) &hich of the followin$ statements can be used to describe a public methoda.-t is accessible to all other classes in the hierarch(b.-t is accessablde onl( to subclasses of its parent classc.-t represents the public interface of its classd.The onl( wa( to $ain access to this method is b( callin$ one of the public classmethodsAns: a0c.2+) &hich of the followin$ t(pes of class members can be part of the internal part of a classa.#ublic instance variablesb.#rivate instance variablesc.#ublic methodsd.#rivate methodsAns: b0d.2) Sou would use the operator to create a sin$le instance of a named class.a.newb.dotAns: a.24) &hich of the followin$ statements correctl( describes the relation between an ob3ect andthe instance variable it storesa./ach new ob3ect has its own distinctive set of instance variables

    b./ach ob3ect has a cop( of the instance variables of its classc.the instance variable of each ob3ect are seperate from the variables of other ob3ectsd.The instance variables of each ob3ect are stored to$ether with the variables of other ob3ectsAns: a0b0c.25) -f no input parameters are specified in a method declaration then the declaration willinclude .a.an empt( set of paranthesesb.the term voidAns: a.;) &hat are the functions of the dot*.) operatora.-t enables (ou to access instance variables of an( ob3ects within a classb.-t enables (ou to store values in instance variables of an ob3ectc.-t is used to call ob3ect methods

    d.-t is to create a new ob3ectAns: a0b0c.1) &hich of the followin$ can be referenced b( this variablea.The instance variables of a class onl(b.The methods of a class onl(c.The instance variables and methods of a classAns: c.2) The this reference is used in con3unction with methods.a.static

  • 8/13/2019 Java MCQ Document

    9/45

    b.nonCstaticAns: b.) &hich of the followin$ operators are used in con3unction with the this and superreferencesa.The new operatorb.The instanceof operator

    c.The dot operatorAns: c.") A constructor is automaticall( called when an ob3ect is instantiateda. trueb. falseAns: a.%) &hen ma( a constructor be called without specif(in$ ar$umentsa. &hen the default constructor is not calledb. &hen the name of the constructor differs from that of the classc. &hen there are no constructors for the classAns: c.+) /ach class in 3ava can have a finali@er methoda. trueb.falseAns: a.) &hen an ob3ect is referenced0 does this mean that it has been identified b( the finali@ermethod for $arba$e collectiona.(esb.noAns: b.4) Gecause finali@e *) belon$s to the 3ava.lan$.Ob3ect class0 it is present in all .a.ob3ectsb.classesc.methodsAns: b.5) -dentif( the true statements about [email protected] class ma( have onl( one finali@e method

    b.Finali@ers are mostl( used with simple classesc.Finali@er overloadin$ is not allowedAns: a0c.";) &hen (ou write finali@e*) method for (our class0 (ou are overridin$ a finali@erinherited from a super class.a.trueb.falseAns: a."1) Java memor( mana$ement mechanism $arba$e collects ob3ects which are no lon$erreferenceda trueb.falseAns: a.

    "2) are ob3ects referenced b( a variable candidates for $arba$e collection when the variable$oes out of scopea (esb. noAns: a.") JavaWs $arba$e collector runs as a priorit( thread waitin$ for priorit( threads torelin'uish the processor.a.hi$hb.low

  • 8/13/2019 Java MCQ Document

    10/45

    Ans: a0b."") The $arba$e collector will run immediatel( when the s(stem is out of memor(a.trueb.falseAns: a."%) Sou can explicitl( drop a ob3ect reference b( settin$ the value of a variable whose data

    t(pe is a reference t(pe to Ans: null"+) &hen mi$ht (our pro$ram wish to run the $arba$e collectera. before it enters a computeCintense section of codeb. before it enters a memor(Cintense section of codec. before ob3ects are finali@edd. when it nows there will be some idle timeAns: a0b0d") For externali@able ob3ects the class is solel( responsible for the external format of itscontentsa.trueb.falseAns: a"4) &hen an ob3ect is stored0 are all of the ob3ects that are reachable from that ob3ect storedas wella.trueb.falseAns: a"5) The default of ob3ects protects private and trancient data0 and supports the of theclassesa.evolutionb.encodin$Ans: b0a.%;) &hich are e(words in Javaa) !X99b) si@eofc) friend

    d) extendse) s(nchroni@edAns : d and e%1) &hen must the main class and the file name coincideAns :&hen class is declared public.%2) &hat are different modifiersAns : public0 private0 protected0 default0 static0 trancient0 volatile0 final0 abstract.%) &hat are access modifiersAns : public0 private0 protected0 default.%") &hat is meant b( 7#assin$ b( value7 and 7 #assin$ b( reference7Ans : ob3ects > pass b( referrenceethods C pass b( value%%) -s a class a subclass of itself

    Ans : A class is a subclass itself.

    %+) &hat modifiers ma( be used with topClevel classAns : public0 abstract0 final.%) &hat is an example of pol(morphism-nner classAnon(mous classesethod overloadin$ethod overridin$

  • 8/13/2019 Java MCQ Document

    11/45

    Ans : c

    #aca$es and interface1) &hat are paca$es what is use of paca$es Ans :The paca$e statement defines a name space in which classes are stored.-f (ou omit the

    paca$e0 the classes are put into the default paca$e.6i$nature... paca$e p$Xse: D -t specifies to which paca$e the classes defined in a file belon$s to. D #aca$e is bothnamin$ and a visibilit( control mechanism.2) &hat is difference between importin$ 73ava.applet.Applet7 and 73ava.applet.D7 Ans :73ava.applet.Applet7 will import onl( the class Applet from the paca$e 3ava.applet&here as 73ava.applet.D7 will import all the classes from 3ava.applet paca$e.) &hat do (ou understand b( paca$e access specifierAns : public: An(thin$ declared as public can be accessed from an(whereprivate: An(thin$ declared in the private can=t be seen outside of its class.default: -t is visible to subclasses as well as to other classes in the same paca$e.") &hat is interface &hat is use of interfaceAns : -t is similar to class which ma( contain method=s si$nature onl( but not bodies.ethods declared in interface are abstract methods. &e can implement man( interfaces on aclass which support the multiple inheritance.%) -s it is necessar( to implement all methods in an interfaceAns : Ses. All the methods have to be implemented.+) &hich is the default access modifier for an interface methodAns : public.) ,an we define a variable in an interface and what t(pe it should be Ans : Ses we can define a variable in an interface. The( are implicitl( final and static.4) &hat is difference between interface and an abstract classAns : All the methods declared inside an -nterface are abstract. &here as abstract class musthave at least one abstract method and others ma( be concrete or abstract.-n -nterface we need not use the e(word abstract for the methods.5) G( default0 all pro$ram import the 3ava.lan$ paca$e.True8False

    Ans : True1;) Java compiler stores the .class files in the path specified in ,9A66#ATIenvironmental variable.True8FalseAns : False

    11) XserCdefined paca$e can also be imported 3ust lie the standard paca$es.True8FalseAns : True12) &hen a pro$ram does not want to handle exception0 the class is used.Ans : Throws1) The main subclass of the /xception class is class.Ans : Nuntime/xception

    1") Onl( subclasses of class ma( be cau$ht or thrown.Ans : Throwable1%) An( userCdefined exception class is a subclass of the class.Ans : /xception1+) The catch clause of the userCdefined exception class should itsGase class catch clause.Ans : /xception1) A is used to separate the hierarch( of the class while declarin$ an-mport statement.

  • 8/13/2019 Java MCQ Document

    12/45

    Ans : #aca$e

    14) All standard classes of Java are included within a paca$e called .Ans : 3ava.lan$15) All the classes in a paca$e can be simultaneousl( imported usin$ .Ans : D

    2;) ,an (ou define a variable inside an -nterface. -f no0 wh( -f (es0 howAns.: S/6. final and static21) Iow man( concrete classes can (ou have inside an interfaceAns.: !one22) ,an (ou extend an interfaceAns.: Ses2) -s it necessar( to implement all the methods of an interface while implementin$ theinterfaceAns.: !o2") -f (ou do not implement all the methods of an interface while implementin$ 0 whatspecifier should (ou use for the class Ans.: abstract2%) Iow do (ou achieve multiple inheritance in JavaAns: Xsin$ interfaces.2+) Iow to declare an interface exampleAns : access class classname implements interface.2) ,an (ou achieve multiple interface throu$h interfacea)Trueb) falseAns : a.24) ,an variables be declared in an interface -f so0 what are the modifiersAns : Ses. final and static are the modifiers can be declared in an interface.25) &hat are the possible access modifiers when implementin$ interface methodsAns : public.;) ,an anon(mous classes be implemented an interfaceAns : Ses.1) -nterfaces can=t be extended.

    a)Trueb)FalseAns : b.2) !ame interfaces without a methodAns : 6eriali@able0 ,loneble < Nemote.) -s it possible to use few methods of an interface in a class -f so0 howAns : Ses. Eeclare the class as abstract.

    /xception Iandlin$1) &hat is the difference between Ythrow= and Ythrows= And it=s applicationAns : /xceptions that are thrown b( 3ava runtime s(stems can be handled b( Tr( and catch

    blocs. &ith throw exception we can handle the exceptions thrown b( the pro$ram itself. -f amethod is capable of causin$ an exception that it does nothandle0 it must specif( this behavior so the callers of the method can $uarda$ainst that exception.2) &hat is the difference between Y/xception= and Yerror= in 3avaAns : /xception and /rror are the subclasses of the Throwable class. /xception class is used forexceptional conditions that user pro$ram should catch. &ith exception class we can subclass tocreate our own custom exception./rror defines exceptions that are not excepted to be cau$ht b( (ou pro$ram. /xample is 6tac

  • 8/13/2019 Java MCQ Document

    13/45

    Overflow.) &hat is YNesource lea=Ans : Freein$ up other resources that mi$ht have been allocated at the be$innin$ of a method.")&hat is the Yfinall(= blocAns : Finall( bloc will execute whether or not an exception is thrown. -f an exception isthrown0 the finall( bloc will execute even if no catch statement match the exception. An(

    time a method is about to return to the caller from inside tr(8catch bloc0 via an uncau$htexception or an explicit return statement0 the finall( clause is also execute.%) ,an we have catch bloc with out tr( bloc -f so whenAns : !o. Tr(8,atch or Tr(8finall( form a unit.+) &hat is the difference between the followin$ statements,atch */xception e)0,atch */rror err)0,atch *Throwable t)Ans :

    ) &hat will happen to the /xception ob3ect after exception handlin$Ans : -t will $o for Zarba$e ,ollector. And frees the memor(.4) Iow man( /xceptions we can define in Ythrows= clauseAns : &e can define multiple exceptions in throws clause.6i$nature is..t(pe methodCname *parameterClist) throws exceptionClist

    5) The finall( bloc is executed when an exception is thrown0 even if no catch matches it.True8FalseAns : True1;) The subclass exception should precede the base class exception when used within the catchclause.True8FalseAns : True11) /xceptions can be cau$ht or rethrown to a callin$ method.

    True8FalseAns : True12) The statements followin$ the throw e(word in a pro$ram are not executed.True8FalseAns : True1) The to6trin$ * ) method in the userCdefined exception class is overridden.True8FalseAns : True

    X9T- TIN/AE-!Z1) &hat are the two t(pes of multitasin$

  • 8/13/2019 Java MCQ Document

    14/45

    Ans : 1.processCbased2.ThreadCbased2) &hat are the two wa(s to create the threadAns : 1.b( implementin$ Nunnable2.b( extendin$ Thread) &hat is the si$nature of the constructor of a thread class

    Ans : Thread*Nunnable threadob06trin$ thread!ame)") &hat are all the methods available in the Nunnable -nterfaceAns : run*)%) &hat is the data t(pe for the method isAlive*) and this method isavailable in which classAns : boolean0 Thread+) &hat are all the methods available in the Thread classAns : 1.isAlive*)2.3oin*).resume*)".suspend*)%.stop*)+.start*).sleep*)4.destro(*)) &hat are all the methods used for -nter Thread communication and what is the class inwhich these methods are definedAns :1. wait*)0notif(*) < notif(all*)2. Ob3ect class4) &hat is the mechanisam defind b( 3ava for the Nesources to be used b( onl( one Thread at atimeAns : 6(nchronisation5) &hat is the procedure to own the moniter b( man( threadsAns : not possible1;) &hat is the unit for 1;;; in the below statementob.sleep*1;;;)Ans : lon$ milliseconds

    11) &hat is the data t(pe for the parameter of the sleep*) methodAns : lon$12) &hat are all the values for the followin$ levelmaxCpriorit(minCpriorit(normalCpriorit(Ans : 1;010%1) &hat is the method available for settin$ the priorit(Ans : set#riorit(*)1") &hat is the default thread at the time of startin$ the pro$ramAns : main thread1%) The word s(nchroni@ed can be used with onl( a method.True8 False

    Ans : False1+) &hich priorit( Thread can prompt the lower primar( ThreadAns : Ii$her #riorit(1) Iow man( threads at a time can access a monitorAns : one14) &hat are all the four states associated in the threadAns : 1. new 2. runnable . bloced ". dead15) The suspend*)method is used to teriminate a threadTrue 8False

  • 8/13/2019 Java MCQ Document

    15/45

    Ans : False2;) The run*) method should necessar( exists in clases created as subclass of threadTrue 8FalseAns : True21) &hen two threads are waitin$ on each other and canWt proceed the pro$rame is said to bein a deadloc

    True8FalseAns : True22) &hich method waits for the thread to die Ans : 3oin*) method

    2) &hich of the followin$ is true1) wait*)0notif(*)0notif(all*) are defined as final < can be called onl( from with in as(nchroni@ed method2) Amon$ wait*)0notif(*)0notif(all*) the wait*) method onl( throws -O/xception) wait*)0notif(*)0notif(all*) < sleep*) are methods of ob3ect class121 < 2102 < Ans : E2") Zarba$e collector thread belon$s to which priorit(Ans : lowCpriorit(2%) &hat is meant b( timeslicin$ or time sharin$Ans : Timeslicin$ is the method of allocatin$ ,#X time to individual threads in a priorit(schedule.2+) &hat is meant b( daemon thread -n 3ava runtime0 what is itWs roleAns : Eaemon thread is a low priorit( thread which runs intermittentl( in the bac$round doin$the $arba$e collection operation for the 3ava runtime s(stem.

    -nheritance1) &hat is the difference between superclass < subclassAns : A super class is a class that is inherited whereas subclass is a class that does theinheritin$.2) &hich e(word is used to inherit a classAns : extends) 6ubclasses methods can access superclass members8 attributes at all timesTrue8FalseAns : False

    ") &hen can subclasses not access superclass membersAns : &hen superclass is declared as private.

    %) &hich class does be$in Java class hierarch(Ans : Ob3ect class+) Ob3ect class is a superclass of all other classesTrue8FalseAns : True) Java supports multiple inheritanceTrue8FalseAns : False4) &hat is inheritance

  • 8/13/2019 Java MCQ Document

    16/45

    Ans : Eerivin$ an ob3ect from an existin$ class. -n the other words0 -nheritance is the process ofinheritin$ all the features from a class5) &hat are the advanta$es of inheritanceAns : Neusabilit( of code and accessibilit( of variables and methods of the superclass b(subclasses.1;) &hich method is used to call the constructors of the superclass from the subclass

    Ans : super*ar$ument)11) &hich is used to execute an( method of the superclass from the subclassAns : super.methodCname*ar$uments)12) &hich methods are used to destro( the ob3ects created b( the constructor methodsAns : finali@e*)1) &hat are abstract classesAns : Abstract classes are those for which instances can=t be created.1") &hat must a class do to implement an interfaceAns: -t must provide all of the methods in the interface and identif( the interface in itsimplements clause.1%) &hich methods in the Ob3ect class are declared as finalAns : $et,lass*)0 notif(*)0 notif(All*)0 and wait*)1+) Final methods can be overridden.True8FalseAns : False1) Eeclaration of methods as final results in faster execution of the pro$ramTrue8FalseAns: True14) Final variables should be declared in the be$innin$True8FalseAns : True15) ,an we declare variable inside a method as final variables &h(Ans : ,annot because0 local variable cannot be declared as final variables.2;) ,an an abstract class ma( be finalAns : An abstract class ma( not be declared as final.21) Eoes a class inherit the constructors of itWs super classAns: A class does not inherit constructors from an( of itWs super classes.

    22) &hat restrictions are placed on method overloadin$Ans: Two methods ma( not have the same name and ar$ument list but different return t(pes.2) &hat restrictions are placed on method overridin$Ans : Overridden methods must have the same name 0 ar$ument list 0 and return t(pe. Theoverridin$ method ma( not limit the access of the method it overridees.The overridin$ methodma( not throw an( exceptions that ma( not be thrown b( the overridden method.2") &hat modifiers ma( be used with an inner class that is a member of an outer classAns : a *nonClocal) inner class ma( be declared as public0 protected0 private0 static0 final orabstract.2%) Iow this*) is used with constructorsAns: this*) is used to invoe a constructor of the same class2+) Iow super*) used with constructorsAns : super*) is used to invoe a super class constructor

    2) &hich of the followin$ statements correctl( describes an interfacea)-tWs a concrete classb)-tWs a superclassc)-tWs a t(pe of abstract classAns: c24) An interface contains methodsa)!onCabstractb)-mplementedc)unimplemented

  • 8/13/2019 Java MCQ Document

    17/45

    Ans:c

    6TN-!Z IA!E9-!Z&hich paca$e does define 6trin$ and 6trin$Guffer classesAns : 3ava.lan$ paca$e.&hich method can be used to obtain the len$th of the 6trin$Ans : len$th* ) method.Iow do (ou concatenate 6trin$sAns : G( usin$ 7 M 7 operator.&hich method can be used to compare two strin$s for e'ualit(Ans : e'uals* ) method.&hich method can be used to perform a comparison between strin$s that i$nores casedifferencesAns : e'uals-$nore,ase* ) method.&hat is the use of valueOf* ) methodAns : valueOf* ) method converts data from its internal format into a humanCreadable form.&hat are the uses of to9ower,ase* ) and toXpper,ase* ) methodsAns : The method to9ower,ase* ) converts all the characters in a strin$ from uppercase tolowercase.The method toXpper,ase* ) converts all the characters in a strin$ from lowercase touppercase.&hich method can be used to find out the total allocated capacit( of a 6trinGufferAns : capacit(* ) method.&hich method can be used to set the len$th of the buffer within a 6trin$Guffer ob3ectAns : set9en$th* ).

    &hat is the difference between 6trin$ and 6trin$GufferAns : 6trin$ ob3ects are constants0 whereas 6trin$Guffer ob3ects are not.6trin$ class supports constant strin$s0 whereas 6trin$Guffer class supports $rowable0 modifiablestrin$s.&hat are wrapper classesAns : &rapper classes are classes that allow primitive t(pes to be accessed as ob3ects.&hich of the followin$ is not a wrapper class6trin$-nte$erGoolean,haracterAns : a.&hat is the output of the followin$ pro$ram

    public class [uestion public static void main*6trin$ ar$sKL) 6trin$ s1 7abc76trin$ s2 7def76trin$ s s1.concat*s2.toXpper,ase* ) )6(stem.out.println*s1Ms2Ms)VVabcdefabcdef

  • 8/13/2019 Java MCQ Document

    18/45

    abcabcE/FE/FabcdefabcE/F!one of the aboveA!6 : c.&hich of the followin$ methods are methods of the 6trin$ classdelete* )

    append* )reverse* )replace* )Ans : d.&hich of the followin$ methods cause the 6trin$ ob3ect referenced b( s to be chan$eds.concat* )s.toXpper,ase* )s.replace* )s.valueOf* )Ans : a and b.6trin$ is a wrapper classTrueFalseAns : b.1) -f (ou run the code below0 what $ets printed out6trin$ snew 6trin$*7Gic(cle7)

    int iGe$in1

    char i/nd

    6(stem.out.println*s.substrin$*iGe$in0i/nd))Gicicc) ic( d) error: no method matchin$ substrin$*int0char)Ans : b.14) Ziven the followin$ declarations

    6trin$ s1new 6trin$*7Iello7)

    6trin$ s2new 6trin$*7there7)

    6trin$ snew 6trin$*)&hich of the followin$ are le$al operationsss1 M s2ss1 C s2c) ss1 < s2 d) ss1

  • 8/13/2019 Java MCQ Document

    19/45

  • 8/13/2019 Java MCQ Document

    20/45

    The /xception class is final and the /rror is not.Goth classes implement Throwable.Ans : a.&hich of the followin$ are trueThe Hoid class extends the ,lass class.The Float class extends the Eouble class.

    The 6(stem class extends the Nuntime class.The -nte$er class extends the !umber class.Ans : d.

    1) &hich of the followin$ will output C".;6(stem.out.println*ath.floor*C".))6(stem.out.println*ath.round*C".))6(stem.out.println*ath.ceil*C".))d) 6(stem.out.println*ath.in*C".))Ans : c.14) &hich of the followin$ are valid statementsa) public class (,alc extends ath b) ath.max*s) c) ath.round*5.5501) d)ath.mod*"01;)e) !one of the above.Ans : e.15) &hat will happen if (ou attempt to compile and run the followin$ code-nte$er tennew -nte$er*1;)

    9on$ ninenew 9on$ *5)

    6(stem.out.println*ten M nine)

    int i1

    6(stem.out.println*i M ten)

    15 followed b( 2;15 followed b( 11/rror: ,anWt convert 3ava lan$ -nte$erd) 1; followed b( 1Ans : c.

    -!#XT 8 OXT#XT : /#9ON-!Z JAHA.-O&hat is meant b( 6tream and what are the t(pes of 6treams and classes of the 6treamsAns : A 6tream is an abstraction that either produces or consumes information.There are two t(pes of 6treams. The( are:G(te 6treams : G(te 6treams provide a convenient means for handlin$ input and output ofb(tes.,haracter 6treams : ,haracter 6treams provide a convenient means for handlin$ input and

    output of characters.G(te 6tream classes : G(te 6treams are defined b( usin$ two abstract classes. The(are:-nput6tream and Output6tream.,haracter 6tream classes : ,haracter 6treams are defined b( usin$ two abstract classes. The(are : Neader and &riter.&hich of the followin$ statements are trueXTF characters are all 4Cbits.XTF characters are all 1+Cbits.XTF characters are all 2"Cbits.

  • 8/13/2019 Java MCQ Document

    21/45

    Xnicode characters are all 1+Cbits.G(tecode characters are all 1+Cbits.Ans : d.&hich of the followin$ statements are true&hen (ou construct an instance of File0 if (ou do not use the filenamin$ semantics of the localmachine0 the constructor will throw an -O/xception.

    &hen (ou construct an instance of File0 if the correspondin$ file does not exist on the local files(stem0 one will be created.&hen an instance of File is $arba$e collected0 the correspondin$ file on the local file s(stem isdeleted.!one of the above.Ans : a0b and c.The File class contains a method that chan$es the current worin$ director(.TrueFalseAns : b.-t is possible to use the File class to list the contents of the current worin$ director(.TrueFalseAns : a.Neaders have methods that can read and return floats and doubles.TrueFalseAns : b.Sou execute the code below in an empt( director(. &hat is the resultFile f1 new File*7dirname7)File f2 new File*f10 7filename7)A new director( called dirname is created in the current worin$ director(.A new director( called dirname is created in the current worin$ director(. A new file calledfilename is created in director( dirname.A new director( called dirname and a new file called filename are created0 both in the currentworin$ director(.A new file called filename is created in the current worin$ director(.

    !o director( is created0 and no file is created.Ans : e.&hat is the difference between the Neader8&riter class hierarch( and the-nput6tream8Output6tream class hierarch(Ans : The Neader8&riter class hierarch( is characterCoriented and the-nput6tream8Output6tream class hierarch( is b(teCoriented.&hat is an -8O filterAns : An -8O filter is an ob3ect that reads from one stream and writes to another0 usuall(alterin$ the data in some wa( as it is passed from one stream to another.&hat is the purpose of the File classAns : The File class is used to create ob3ects that provide access to the files and directories ofa local file s(stem.&hat interface must an ob3ect implement before it can be written to a stream as an ob3ect

    Ans : An ob3ect must implement the 6eriali@able or /xternali@able interface before it can bewritten to a stream as an ob3ect.&hat is the difference between the File and NandomAccessFile classesAns : The File class encapsulates the files and directories of the local file s(stem. TheNandomAccessFile class provides the methods needed to directl( access data contained in an(part of a file.&hat class allows (ou to read ob3ects directl( from a streamAns : The Ob3ect-nput6tream class supports the readin$ of ob3ects from input streams.&hat value does read* ) return when it has reached the end of a file

  • 8/13/2019 Java MCQ Document

    22/45

    Ans : The read* ) method returns > 1 when it has reached the end of a file.&hat value does read9ine* ) return when it has reached the end of a fileAns : The read9ine* ) method returns null when it has reached the end of a file.Iow man( bits are used to represent Xnicode0 A6,--0 XTFC1+ and XTFC4 charactersAns : Xnicode re'uires 1+Cbits and A6,-- re'uires 4Cbits. Althou$h the A6,-- character set usesonl( 1Cbits0 it is usuall( represented as 4Cbits. XTFC4 represents characters usin$ 40 1+ and 14C

    bit patterns. XTFC1+ uses 1+Cbit and lar$er bit patterns.&hich of the followin$ are trueThe -nput6tream and Output6tream classes are b(teCoriented.The Ob3ect-nput6tream and Ob3ectOutput6tream do not support seriali@ed ob3ect input andoutput.The Neader and &riter classes are characterCoriented.The Neader and &riter classes are the preferred solution to seriali@ed ob3ect output.Ans : a and c.&hich of the followin$ are true about -8O filtersFilters are supported on input0 but not on output.Filters are supported b( the -nput6tream8Output6tream class hierarch(0 but not b( theNeader8&riter class hierarch(.Filters read from one stream and write to another.A filter ma( alter data that is read from one stream and written to another.Ans : c and d.&hich of the followin$ are trueAn( Xnicode character is represented usin$ 1+Cbits.Cbits are needed to represent an( A6,-- character.XTFC4 characters are represented usin$ onl( 4Cbits.XTFC1+ characters are represented usin$ onl( 1+Cbits.Ans : a and b.&hich of the followin$ are trueThe 6eriali@able interface is used to identif( ob3ects that ma( be written to an output stream.The /xternali@able interface is implemented b( classes that control the wa( in which theirob3ects are [email protected] 6eriali@able interface extends the /xternali@able interface.The /xternali@able interface extends the 6eriali@able interface.

    Ans : a0 b and d.&hich of the followin$ are true about the File classA File ob3ect can be used to chan$e the current worin$ director(.A File ob3ect can be used to access the files in the current director(.&hen a File ob3ect is created0 a correspondin$ director( or file is created in the local files(stem.File ob3ects are used to access files and directories on the local file s(stem.File ob3ects can be $arba$e collected.&hen a File ob3ect is $arba$e collected0 the correspondin$ file or director( is deleted.Ans : b0 d and e.Iow do (ou create a Neader ob3ect from an -nput6tream ob3ectXse the static createNeader* ) method of -nput6tream class.Xse the static createNeader* ) method of Neader class.

    ,reate an -nput6treamNeader ob3ect0 passin$ the -nput6tream ob3ect as an ar$ument to the-nput6treamNeader constructor.,reate an Output6treamNeader ob3ect0 passin$ the -nput6tream ob3ect as an ar$ument to theOutput6treamNeader constructor.Ans : c.&hich of the followin$ are true&riter classes can be used to write characters to output streams usin$ different characterencodin$s.&riter classes can be used to write Xnicode characters to output streams.

  • 8/13/2019 Java MCQ Document

    23/45

    &riter classes have methods that support the writin$ of the values of an( Java primitive t(peto output streams.&riter classes have methods that support the writin$ of ob3ects to output streams.Ans : a and b.The isFile* ) method returns a boolean value dependin$ on whether the file ob3ect is a file or adirector(.

    True.False.Ans : a.Neadin$ or writin$ can be done even after closin$ the input8output source.True.False.Ans : b.

    The method helps in clearin$ the buffer.Ans : flush* ).The 6(stem.err method is used to print error messa$e.True.False.Ans : a.&hat is meant b( 6treamToeni@erAns : 6treamToeni@er breas up -nput6tream into toens that are delimited b( sets ofcharacters.-t has the constructor : 6treamToeni@er*Neader in6tream).Iere in6tream must be some form of Neader.&hat is 6eriali@ation and deseriali@ationAns : 6eriali@ation is the process of writin$ the state of an ob3ect to a b(te stream.Eeseriali@ation is the process of restorin$ these ob3ects.;) &hich of the followin$ can (ou perform usin$ the File classa) ,han$e the current director( b) Neturn the name of the parent director( c) Eelete a file d)Find if a file contains text or binar( informationAns : b and c.1)Iow can (ou chan$e the current worin$ director( usin$ an instance of the File class called

    File!ameFile!ame.chdir*7Eir!ame7).File!ame.cd*7Eir!ame7).File!ame.cwd*7Eir!ame7).The File class does not support directl( chan$in$ the current director(.Ans : d.

  • 8/13/2019 Java MCQ Document

    24/45

    /H/!T IA!E9-!ZThe event dele$ation model0 introduced in release 1.1 of the JE0 is full( compatible with theevent model.TrueFalseAns : b.A component subclass that has executed enable/vents* ) to enable processin$ of a certain ind

    of event cannot also use an adapter as a listener for the same ind of event.TrueFalseAns : b.&hat is the hi$hestClevel event class of the eventCdele$ation modelAns : The 3ava.util.eventOb3ect class is the hi$hestClevel class in the eventCdele$ationhierarch(.&hat interface is extended b( A&T event listenersAns : All A&T event listeners extend the 3ava.util./vent9istener interface.

  • 8/13/2019 Java MCQ Document

    25/45

    &hat class is the top of the A&T event hierarch(Ans : The 3ava.awt.A&T/vent class is the hi$hestClevel class in the A&T event class hierarch(.&hat event results from the clicin$ of a buttonAns : The Action/vent event is $enerated as the result of the clicin$ of a button.&hat is the relationship between an eventClistener interface and an eventCadapter classAns : An eventClistener interface defines the methods that must be implemented b( an event

    handler for a particular ind of event.An event adapter provides a default implementation of an eventClistener interface.-n which paca$e are most of the A&T events that support the eventCdele$ation modeldefinedAns : ost of the A&T>related events of the eventCdele$ation model are defined in the3ava.awt.event paca$e. The A&T/vent class is defined in the 3ava.awt paca$e.&hat is the advanta$e of the eventCdele$ation model over the earlier eventCinheritancemodelAns : The eventCdele$ation has two advanta$es over the eventCinheritance model. The( are :-t enables event handlin$ b( ob3ects other than the ones that $enerate the events. Thisallows a clean separation between a component=s desi$n and its use.-t performs much better in applications where man( events are $enerated. Thisperformance improvement is due to the fact that the eventCdele$ation model does nothave to repeatedl( process unhandled events0 as is the case of the eventCinheritancemodel.&hat is the purpose of the enable/vents* ) methodAns :The enable/vents* ) method is used to enable an event for a particular ob3ect.&hich of the followin$ are trueThe eventCinheritance model has replaced the eventCdele$ation model.The eventCinheritance model is more efficient than the eventCdele$ation model.The eventCdele$ation model uses event listeners to define the methods of eventChandlin$classes.The eventCdele$ation model uses the handle/vent* ) method to support event handlin$.Ans : c.&hich of the followin$ is the hi$hest class in the eventCdele$ation model3ava.util./vent9istener3ava.util./ventOb3ect

    3ava.awt.A&T/vent3ava.awt.event.A&T/ventAns : b.&hen two or more ob3ects are added as listeners for the same event0 which listener is firstinvoed to handle the eventThe first ob3ect that was added as listener.The last ob3ect that was added as listener.There is no wa( to determine which listener will be invoed first.-t is impossible to have more than one listener for a $iven event.Ans : c.&hich of the followin$ components $enerate action eventsGuttons9abels

    ,hec boxes&indowsAns : a.&hich of the followin$ are trueA TextField ob3ect ma( $enerate an Action/vent.A TextArea ob3ect ma( $enerate an Action/vent.A Gutton ob3ect ma( $enerate an Action/vent.A enu-tem ob3ect ma( $enerate an Action/vent.Ans : a0c and d.

  • 8/13/2019 Java MCQ Document

    26/45

    &hich of the followin$ are trueThe ouse9istener interface defines methods for handlin$ mouse clics.The ouseotion9istener interface defines methods for handlin$ mouse clics.The ouse,lic9istener interface defines methods for handlin$ mouse clics.The Action9istener interface defines methods for handlin$ the clicin$ of a button.Ans : a and d.

    6uppose that (ou want to have an ob3ect eh handle the Text/vent of a TextArea ob3ect t. Iowshould (ou add eh as the event handler for tt.addText9istener*eh)eh.addText9istener*t)addText9istener*eh.t)addText9istener*t0eh)Ans : a.&hat is the preferred wa( to handle an ob3ect=s events in Java 2Override the ob3ect=s handle/vent* ) method.Add one or more event listeners to handle the events.Iave the ob3ect override its process/vent* ) methods.Iave the ob3ect override its dispatch/vent* ) methods.Ans : b.&hich of the followin$ are trueA component ma( handle its own events b( addin$ itself as an event listener.A component ma( handle its own events b( overridin$ its eventCdispatchin$ method.A component ma( not handle oits own events.A component ma( handle its own events onl( if it implements the handle/vent* ) method.Ans : a and b.

    A##9/T6&hat is an Applet 6hould applets have constructors

    Ans : Applet is a d(namic and interactive pro$ram that runs inside a &eb pa$edispla(ed b( a Java capable browser. &e don=t have the concept of ,onstructors in Applets.Iow do we read number information from m( applet=s parameters0 $iven that Applet=s$et#arameter*) method returns a strin$Ans : Xse the parse-nt*) method in the -nte$er ,lass0 the Float*6trin$) constructor in the,lass Float0 or the Eouble*6trin$) constructor in the class Eouble.Iow can - arran$e for different applets on a web pa$e to communicate with each otherAns : !ame (our applets inside the Applet ta$ and invoe Applet,ontext=s $etApplet*)method in (our applet code to obtain references to the other applets on the pa$e.

  • 8/13/2019 Java MCQ Document

    27/45

    Iow do - select a XN9 from m( Applet and send the browser to that pa$eAns : As the applet for its applet context and invoe showEocument*) on that context ob3ect./$. XN9 tar$etXN96trin$ XN96trin$Applet,ontext context $etApplet,ontext*)tr(

    tar$etXN 9 new XN9*XN96trin$)V catch *alformed XN9/xception e)88 ,ode for recover from the exceptionVcontext. showEocument *tar$etXN9),an applets on different pa$es communicate with each otherAns : !o. !ot Eirectl(. The applets will exchan$e the information at one meetin$ placeeither on the local file s(stem or at remote s(stem.Iow do Applets differ from ApplicationsAns : Appln: 6tand AloneApplet: !eeds no explicit installation on local m8c.Appln: /xecution starts with main*) method.Applet: /xecution starts with init*) method.Appln: a( or ma( not be a ZX-Applet: ust run within a ZX- *Xsin$ A&T)Iow do - determine the width and hei$ht of m( applicationAns : Xse the $et6i@e*) method0 which the Applet class inherits from the ,omponentclass in the Java.awt paca$e. The $et6i@e*) method returns the si@e of the applet asa Eimension ob3ect0 from which (ou extract separate width0 hei$ht fields./$. Eimension dim $et6i@e *)int appletwidth dim.width *)4) &hat is Applet6tub -nterfaceAns : The applet stub interface provides the means b( which an applet and the browsercommunicate. Sour code will not t(picall( implement this interface.-t is essential to have both the .3ava file and the .html file of an applet in the samedirector(.True.

    False.Ans : b.The ta$ contains two attributes namel( and .Ans : !ame 0 value.

    #assin$ values to parameters is done in the file of an applet.Ans : .html.12) &hat ta$s are mandator( when creatin$ IT9 to displa( an appletname0 hei$ht0 widthcode0 namecodebase0 hei$ht0 widthd) code0 hei$ht0 widthAns : d.

    Applet=s $et#arameter* ) method can be used to $et parameter values.True.False.Ans : a.&hat are the Applet=s 9ife ,(cle methods /xplain themAns : init* ) method C ,an be called when an applet is first loaded.start* ) method C ,an be called each time an applet is started.paint* ) method C ,an be called when the applet is minimi@ed or refreshed.stop* ) method C ,an be called when the browser moves off the applet=s pa$e.

  • 8/13/2019 Java MCQ Document

    28/45

    destro(* ) method C ,an be called when the browser is finished with the applet.&hat are the Applet=s information methodsAns : $etApplet-nfo* ) method : Neturns a strin$ describin$ the applet0 its author 0cop(ri$ht information0 etc.$et#arameter-nfo* ) method : Neturns an arra( of strin$ describin$ the applet=s parameters.All Applets are subclasses of Applet.

    True.False.Ans : a.All Applets must import 3ava.applet and 3ava.awt.True.False.Ans : a.&hat are the steps involved in Applet developmentAns : a) /dit a Java source file0b) ,ompile (our pro$ram andc) /xecute the appletviewer0 specif(in$ the name of (our applet=s source file.Applets are executed b( the console based Java runCtime interpreter.True.False.Ans : b.&hich classes and interfaces does Applet class consistAns : Applet class consists of a sin$le class0 the Applet class and three interfaces:Applet,ontext0Applet6tub and Audio,lip.&hat is the se'uence for callin$ the methods b( A&T for appletsAns : &hen an applet be$ins0 the A&T calls the followin$ methods0 in this se'uence.init* )start* )paint* )&hen an applet is terminated0 the followin$ se'uence of method cals taes place :stop* )destro(* )

    &hich method is used to output a strin$ to an appletAns : draw6trin$ * ) method./ver( color is created from an NZG value.True. FalseAns : a.

    A&T : &-!EO&60 ZNA#I-,6 A!E FO!T6Iow would (ou set the color of a $raphics context called $ to c(an$.set,olor*,olor.c(an)$.set,urrent,olor*c(an)$.set,olor*7,olor.c(an7)$.set,olor*7c(an=)

    $.set,olor*new ,olor*c(an))Ans : a.The code below draws a line. &hat color is the line$.set,olor*,olor.red.$reen.(ellow.red.c(an)$.draw9ine*;0 ;0 1;;01;;)NedZreenSellow,(an

  • 8/13/2019 Java MCQ Document

    29/45

    GlacAns : d.&hat does the followin$ code draw$.set,olor*,olor.blac)$.draw9ine*1;0 1;0 1;0 %;)$.set,olor*,olor.N/E)

    $.drawNect*1;;0 1;;0 1%;0 1%;)A red vertical line that is "; pixels lon$ and a red s'uare with sides of 1%; pixelsA blac vertical line that is "; pixels lon$ and a red s'uare with sides of 1%; pixelsA blac vertical line that is %; pixels lon$ and a red s'uare with sides of 1%; pixelsA red vertical line that is %; pixels lon$ and a red s'uare with sides of 1%; pixelsA blac vertical line that is "; pixels lon$ and a red s'uare with sides of 1;; pixelAns : b.&hich of the statements below are trueA pol(line is alwa(s filled.b) A pol(line can not be filled.c) A pol($on is alwa(s filled.d) A pol($on is alwa(s closede) A pol($on ma( be filled or not filledAns : b0 d and e.&hat code would (ou use to construct a 2"Cpoint bold serif fontnew Font*Font.6/N-F0 2"0Font.GO9E)new Font*76/N-F70 2"0 GO9E7)new Font*7GO9E 70 2"0Font.6/N-F)new Font*76/N-F70 Font.GO9E02")new Font*Font.6/N-F0 7GO9E70 2")Ans : d.&hat does the followin$ paint* ) method draw#ublic void paint*Zraphics $) $.draw6trin$*7'uestion \+701;0;)VThe strin$ 7'uestion \+70 with its topCleft corner at 1;0;A little s'ui$$le comin$ down from the top of the component0 a little wa( in from the left

    ed$eAns : b.

    &hat does the followin$ paint* ) method draw#ublic void paint*Zraphics $) $.draw6trin$*7'uestion \+701;0;)VA circle at *1;;0 1;;) with radius of ""A circle at *1;;0 "") with radius of 1;;A circle at *1;;0 "") with radius of ""The code does not compileAns : d.

    4)&hat is relationship between the ,anvas class and the Zraphics classAns : A ,anvas ob3ect provides access to a Zraphics ob3ect via its paint* ) method.&hat are the ,omponent subclasses that support paintin$.Ans : The ,anvas0 Frame0 #anel and Applet classes support paintin$.&hat is the difference between the paint* ) and repaint* ) methodAns : The paint* ) method supports paintin$ via a Zraphics ob3ect. The repaint* ) method isusedto cause paint* ) to be invoed b( the A&T paintin$ method.&hat is the difference between the Font and Fontetrics classes

  • 8/13/2019 Java MCQ Document

    30/45

  • 8/13/2019 Java MCQ Document

    31/45

    of the word Eoll( will be seen at the top of the form0 with the top hidden. d) The strin$ 7Eoll(7will be shown at the bottom of the formAns : c.2;) &here $ is a $raphics instance what will the followin$ code draw on the screen.$.fillArc*"%05;0%;0%;05;014;)a) An arc bounded b( a box of hei$ht "%0 width 5; with a centre point of %;0%;0 startin$ at an

    an$le of 5; de$rees traversin$ throu$h 14; de$rees counter clocwise.b) An arc bounded b( a box of hei$ht %;0 width %;0 with a centre point of "%05; startin$ at anan$le of 5; de$rees traversin$ throu$h 14; de$rees clocwise.c) An arc bounded b( a box of hei$ht %;0 width %;0 with a top left at coordinates of "%0 5;0startin$ at 5; de$rees and traversin$ throu$h 14; de$rees counter clocwise.d) An arc startin$ at "% de$rees0 traversin$ throu$h 5; de$rees clocwise bounded b( a box ofhei$ht %;0 width %; with a centre point of 5;0 14;.Ans : c.21) Ziven the followin$ code import 3ava.awt.Dpublic class 6etF extends Framepublic staticvoid main*6trin$ ar$vKL)6etF s new 6etF*)s.set6i@e*;;02;;)s.setHisible*true)VV Iow could(ou set the frame surface color to pina)s.setGac$round*,olor.pin)b)s.set,olor*#-!)c)s.Gac$round*pin)d)s.color,olor.pinAns : a.

    A&T: ,O!TNO960 9ASOXT A!AZ/N6 A!E /!X6&hat is meant b( ,ontrols and what are different t(pes of controlsAns : ,ontrols are componenets that allow a user to interact with (our application.The A&T supports the followin$ t(pes of controls:9abels#ush buttons,hec boxes,hoice lists9ists6croll bars

    Text componentsThese controls are subclasses of ,omponent.Sou want to construct a text area that is 4; characterCwidths wide and 1; characterChei$htstall. &hat code do (ou usenew TextArea*4;0 1;)new TextArea*1;0 4;)Ans: b.A text field has a variableCwidth font. -t is constructed b( callin$ newTextField*7iiiii7). &hat happens if (ou chan$e the contents of the text field to7wwwww7 *Gear in mind that is one of the narrowest characters0 and w is one of the widest.)The text field becomes wider.The text field becomes narrower.The text field sta(s the same width to see the entire contents (ou will have to scroll b( usin$

    the ] and ^ e(s.The text field sta(s the same width to see the entire contents (ou will have to scroll b( usin$the text field=s hori@ontal scroll bar.Ans : c.The ,hecboxZroup class is a subclass of the ,omponent class.TrueFalseAns : b.%) &hat are the immediate super classes of the followin$ classes

  • 8/13/2019 Java MCQ Document

    32/45

    a) ,ontainer classb) enu,omponent classc) Eialo$ classd) Applet classe) enu classAns : a) ,ontainer C ,omponent

    b) enu,omponent C Ob3ectc) Eialo$ C &indowd) Applet C #anele) enu C enu-tem+) &hat are the 6ub,lass of Textcomponent ,lassAns : TextField and TextArea) &hich method of the component class is used to set the position and the si@e of acomponentAns : setGounds*)4) &hich Text,omponent method is used to set a Text,omponent to the readConl( stateAns : set/ditable*)5) Iow can the ,hecbox class be used to create a radio buttonAns : G( associatin$ ,hecbox ob3ects with a ,hecboxZroup.1;) &hat ,hecbox method allows (ou to tell if a ,hecbox is checedAns : $et6tate*)11) &hich ,omponent method is used to access a componentWs immediate ,ontainer$etHisible*)$et-mmediate$et#arent*)$et,ontainerAns : c.12) &hat methods are used to $et and set the text label displa(ed b( a Gutton ob3ectAns : $et9abel* ) and set9abel* )1) &hat is the difference between a ,hoice and a 9istAns : A ,hoice is displa(ed in a compact form that re'uires (ou to pull it down to see the list ofavailable choices. Onl( one item ma( be selected from a ,hoice.A 9ist ma( be displa(ed in such a wa( that several 9ist items are visible. A 9ist supports the

    selection of one or more 9ist items.1") &hich ,ontainer method is used to cause a container to be laid out and redispla(edAns : validate* )1%) &hat is the difference between a 6collbar and a 6crollpaneAns : A 6crollbar is a ,omponent0 but not a ,ontainer.A 6crollpane is a ,ontainer and handles its own events and performs its ownscrollin$.1+) &hich ,omponent subclass is used for drawin$ and paintin$Ans : ,anvas.1) &hich of the followin$ are direct or indirect subclasses of ,omponentGutton9abel,hecboxenu-tem

    ToolbarFrameAns : a0 b and e.14) &hich of the followin$ are direct or indirect subclasses of ,ontainerFrameTextAreaenuGarFileEialo$Applet

  • 8/13/2019 Java MCQ Document

    33/45

    Ans : a0d and e.15) &hich method is used to set the text of a 9abel ob3ectsetText* )set9abel* )setText9abel* )set9abelText* )

    Ans : a.2;) &hich constructor creates a TextArea with 1; rows and 2; columnsnew TextArea*1;0 2;)new TextArea*2;0 1;)new TextArea*new Nows*1;)0 new columns*2;))new TextArea*2;;)Ans : a.*Xsa$e is TextArea*rows0 columns)21) &hich of the followin$ creates a 9ist with % visible items and multiple selection enablednew 9ist*%0 true)new 9ist*true0 %)new 9ist*%0 false)new 9ist*false0%)Ans : a.KXsa$e is 9ist*rows0 multipleode)L22) &hich are true about the ,ontainer classThe validate* ) method is used to cause a ,ontainer to be laid out and redispla(ed.The add* ) method is used to add a ,omponent to a ,ontainer.The $etGorder* ) method returns information about a ,ontainer=s insets.The $et,omponent* ) method is used to access a ,omponent that is contained in a ,ontainer.Ans : a0 b and d.2) 6uppose a #anel is added to a Frame and a Gutton is added to the #anel. -f the Frame=s fontis set to 12Cpoint TimesNoman0 the #anel=s font is set to 1;Cpoint TimesNoman0 and theGutton=s font is not set0 what font will be used to dispal( the Gutton=s label12Cpoint TimesNoman11Cpoint TimesNoman

    1;Cpoint TimesNoman5Cpoint TimesNomanAns : c.A Frame=s bac$round color is set to ,olor.Sellow0 and a Gutton=s bac$round color is to,olor.Glue. 6uppose the Gutton is added to a #anel0 which is added to the Frame. &hatbac$round color will be used with the #anel,olr.Sellow,olor.Glue,olor.Zreen,olor.&hiteAns : a.2%) &hich method will cause a Frame to be displa(edshow* )

    setHisible* )displa(* )displa(Frame* )Ans : a and b.2+) All the componenet classes and container classes are derived from class.Ans : Ob3ect.2) &hich method of the container class can be used to add components to a #anel.Ans : add * ) method.24) &hat are the subclasses of the ,ontainer class

  • 8/13/2019 Java MCQ Document

    34/45

    Ans : The ,ontainer class has three ma3or subclasses. The( are :&indow#anel6croll#ane25) The ,hoice component allows multiple selection.True.

    False.Ans : b.;) The 9ist component does not $enerate an( events.True.False.Ans : b.1) &hich components are used to $et text input from the user.Ans : TextField and TextArea.2) &hich ob3ect is needed to $roup ,hecboxes to mae them exclusiveAns : ,hecboxZroup.) &hich of the followin$ components allow multiple selections!onCexclusive ,hecboxes.Nadio buttons.,hoice.9ist.Ans : a and d.") &hat are the t(pes of ,hecboxes and what is the difference between themAns : Java supports two t(pes of ,hecboxes. The( are : /xclusive and !onCexclusive.-n case of exclusive ,hecboxes0 onl( one amon$ a $roup of items can be selected at a time. - fan item from the $roup is selected0 the checbox currentl( checed is deselected and the newselection is hi$hli$hted. The exclusive ,hecboxes are also called as Nadio buttons.The nonCexclusive checboxes are not $rouped to$ether and each one can be selectedindependent of the other.%) &hat is a 9a(out ana$er and what are the different 9a(out ana$ers available in 3ava.awtand what is the default 9a(out mana$er for the panal and the panal subclassesAns: A la(out ana$er is an ob3ect that is used to or$ani@e components in a container.The different la(outs available in 3ava.awt are :

    Flow9a(out0 Gorder9a(out0 ,ard9a(out0 Zrid9a(out and ZridGa$ 9a(out.The default 9a(out ana$er of #anal and #anal sub classes is Flow9a(out7.+) ,an - exert control over the si@e and placement of components in m( interfaceAns : Ses.m(#anal.set9a(out*null)m(#anal.setbounds*2;02;02;;02;;)) ,an - add the same component to more than one containerAns : !o. Addin$ a component to a container automaticall( removes it from an( previousparent*container).4) Iow do - specif( where a window is to be placedAns : Xse setGounds0 set6i@e0 or set9ocation methods to implement this.setGounds*int x0 int (0 int width0 int hei$ht)setGounds*Nectan$le r)

    set6i@e*int width0 int hei$ht)set6i@e*Eimension d)set9ocation*int x0 int ()set9ocation*#oint p)

    5) Iow can we create a borderless windowAns : ,reate an instance of the &indow class0 $ive it a si@e0 and show it on the screen.e$. Frame aFrame ......&indow a&indow new &indow*aFrame)

  • 8/13/2019 Java MCQ Document

    35/45

    a&indow.set9a(out*new Flow9a(out*))a&indow.add*new Gutton*7#ress e7))a&indow.$etGounds*%;0%;02;;02;;)a&indow.show*)

    ";) ,an - create a nonCresi@able windows -f so0 how

    Ans: Ses. G( usin$ setNesi@able*) method in class Frame."1) &hat is the default 9a(out ana$er for the &indow and &indow subclasses*Frame0Eialo$)Ans : Gorder9a(out*)."2) Iow are the elements of different la(outs or$ani@edAns : Flow9a(out : The elements of a Flow9a(out are or$ani@ed in a top to bottom0 left to ri$htfashion.Gorder9a(out : The elements of a Gorder9a(out are or$ani@ed at theborders *!orth0 6outh0 /ast and &est) and the center of acontainer.,ard9a(out : The elements of a ,ard9a(out are staced0 one on top of the other0 lie a dec ofcards.Zrid9a(out : The elements of a Zrid9a(out are of e'ual si@e and are laid out usin$ the s'uareof a $rid.ZridGa$9a(out : The elements of a ZridGa$9a(out are or$ani@ed accordin$ to a $rid.Iowever0the elements are of different si@es and ma( occup(more than one row or column of the $rid. -n addition0 the rows and columns ma( have differentsi@es.") &hich containers use a Gorder9a(out as their default la(outAns : The &indow0 Frame and Eialo$ classes use a Gorder9a(out as their default la(out.

    "") &hich containers use a Flow9a(out as their default la(outAns : The #anel and the Applet classes use the Flow9a(out as their default la(out."%) &hat is the preferred si@e of a componentAns : The preferred si@e of a component si@e that will allow the component to displa(normall(."+) &hich method is method to set the la(out of a container

    start9a(out* )init9a(out* )la(out,ontainer* )set9a(out* )Ans : d.") &hich method returns the preferred si@e of a component$et#referred6i@e* )$et#referred* )$etNe'uired6i@e* )$et9a(out* )Ans : a.

    "4) &hich la(out should (ou use to or$ani@e the components of a container in atabular form,ard9a(outGoreder9a(outFlow9a(outZrid9a(out

  • 8/13/2019 Java MCQ Document

    36/45

    Ans : d.An application has a frame that uses a Gorder la(out mana$er. &h( is it probabl( not a $oodidea to put a vertical scroll bar at !orth in the frameThe scroll bar=s hei$ht would be its preferred hei$ht0 which is not liel( to be enou$h.The scroll bar=s width would be the entire width of the frame0 which would be much widerthan necessar(.

    Goth a and b.!either a nor b. There is no problem with the la(out as described.Ans : c.&hat is the default la(outs for a applet0 a frame and a panelAns : For an applet and a panel0 Flow la(out is the default la(out0 whereas Gorder la(out isdefault la(out for a frame.-f a frame uses a Zrid la(out mana$er and does not contain an( panels0 then all thecomponents within the frame are the same width and hei$ht.TrueFalse.Ans : a.-f a frame uses its default la(out mana$er and does not contain an( panels0 then all thecomponents within the frame are the same width and hei$ht.TrueFalse.Ans : b.&ith a Gorder la(out mana$er0 the component at ,enter $ets all the space that is left over0after the components at !orth and 6outh have been considered.TrueFalseAns : b.An Applet has its 9a(out ana$er set to the default of Flow9a(out. &hat code would be thecorrect to chan$e to another 9a(out ana$erset9a(outana$er*new Zrid9a(out*))set9a(out*new Zrid9a(out*202))c) setZrid9a(out*2020)) d setGorder9a(out*)Ans : b.

    %%) Iow do (ou indicate where a component will be positioned usin$ Flowla(outa) !orth0 6outh0/ast0&estb) Assi$n a row8column $rid referencec) #ass a 8S percenta$eparameter to the add methodd) Eo nothin$0 the Flow9a(out will position the componentAns :d.

    %+) Iow do (ou chan$e the current la(out mana$er for a containera) Xse the set9a(out methodb) Once created (ou cannot chan$e the current la(out mana$er ofa componentc) Xse the set9a(outana$er methodd) Xse the update9a(out methodAns :a.%)&hen usin$ the ZridGa$9a(out mana$er0 each new component re'uires a new instance ofthe ZridGa$,onstraints class. -s this statement true or false

    a) trueb) falseAns : b.%4) &hich of the followin$ statements are truea)The default la(out mana$er for an Applet is Flow9a(out b) The default la(out mana$er for anapplication is Flow9a(out c) A la(out mana$er must be assi$ned to an Applet before the set6i@emethod is called d) The Flow9a(out mana$er attempts to honor the preferred si@e of an(componentsAns : a and d.%5) &hich method does displa( the messa$es whenever there is an item selection or

  • 8/13/2019 Java MCQ Document

    37/45

    deselection of the ,hecboxenu-tem menuAns : item6tate,han$ed method.+;) &hich is a dual state menu itemAns : ,hecboxenu-tem.+1) &hich method can be used to enable8diable a checbox menu itemAns : set6tate*boolean).

    &hich of the followin$ ma( a menu containA separatorA chec boxA menuA buttonA panelAns : a and c.&hich of the followin$ ma( contain a menu barA panelA frameAn appletA menu barA menuAns : b+") &hat is the difference between a enu-tem and a ,hecboxenu-temAns : The ,hecboxenu-tem class extends the enu-tem class to support a menu itemthat ma( be checed or uncheced.+%) &hich of the followin$ are trueA Eialo$ can have a enuGar.enu-tem extends enu.A enu-tem can be added to a enu.A enu can be added to a enu.Ans : c and d.

    7document.write*lubidstrin$)88CC_

    &hich colour is used to indicate instance methods in the standard 73avadoc7 formatdocumentation:1) blue2) red) purple") oran$eAnswer : 2explain-n JE 1.1 the variabels0 methods and constructors are colour coded to simplif(theiridentification.end/xplain&hat is the correct orderin$ for the import0 class and paca$e declarations when found in asin$le file

    1) paca$e0 import0 class2) class0 import0 paca$e) import0 paca$e0 class") paca$e0 class0 importAnswer : 1explainThis is m( explanation for 'uestion 2end/xplain&hich methods can be le$all( applied to a strin$ ob3ect

  • 8/13/2019 Java MCQ Document

    38/45

    *ultiple)1) e'uals*6trin$)2) e'uals*Ob3ect)) trim*)") round*)%) to6trin$*)

    Answer : 10200%&hat is the parameter specification for the public static void main method*multiple)1) 6trin$ ar$s KL2) 6trin$ KL ar$s) 6trin$s ar$s KL") 6trin$ ar$sAnswer : 102&hat does the @eroth element of the strin$ arra( passed to the public static void main methodcontain*multiple)1) The name of the pro$ram2) The number of ar$uments) The first ar$ument if one is presentAnswer : &hich of the followin$ are Java e(words*multiple)1) $oto2) malloc) extends") FA96/Answer : &hat will be the result of compilin$ the followin$ code:public class Test public static void main *6trin$ ar$s KL) int a$ea$e a$e M 1

    6(stem.out.println*7The a$e is 7 M a$e)VV1) ,ompiles and runs with no output2) ,ompiles and runs printin$ out The a$e is 1) ,ompiles but $enerates a runtime error") Eoes not compile%) ,ompiles but $enerates a compile time errorAnswer : "&hich of these is the correct format to use to create the literal char value a*multiple)1) WaW2) 7a7

    ) new ,haracter*a)") `;;;aAnswer : 1&hat is the le$al ran$e of a b(te inte$ral t(pe1) ; C +%0 %%2) *C124) C 12) *C20+4) C 20+") *C2%+) C 2%%Answer : 2

  • 8/13/2019 Java MCQ Document

    39/45

    &hich of the followin$ is ille$al:1) int i 22) float f "%.;) double d "%.;Answer 2&hat will be the result of compilin$ the followin$ code:

    public class Test static int a$epublic static void main *6trin$ ar$s KL) a$e a$e M 16(stem.out.println*7The a$e is 7 M a$e)VV1) ,ompiles and runs with no output2) ,ompiles and runs printin$ out The a$e is 1) ,ompiles but $enerates a runtime error") Eoes not compile%) ,ompiles but $enerates a compile time errorAnswer : 2&hich of the followin$ are correct*multiple)1) 124 __ 1 $ives +"2) 124 ___ 1 $ives +") 124 __ 1 $ives C+"") 124 ___ 1 $ives C+"Answer : 1&hich of the followin$ return true*multiple)1) 73ohn7 new 6trin$*73ohn7)2) 73ohn7.e'uals*73ohn7)) 73ohn7 73ohn7") 73ohn7.e'uals*new Gutton*73ohn7))Answer : 2

    &hich of the followin$ do not lead to a runtime error*multiple)1) 73ohn7 M 7 was 7 M 7 here72) 73ohn7 M ) M %") % M %.%answer 10200"&hich of the followin$ are so called 7short circuit7 lo$ical operators*multiple)1)