2081 quiz questions exam

Upload: nipun-arora

Post on 23-Feb-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/24/2019 2081 Quiz Questions Exam

    1/15

    2081 Quiz QuestionsWeek 2

    Q1. Of the three types of mobile apps which type(s) has (hae) the

    potential to write once then !istribute to many platforms"#ybri! $pps

    %obile apps

    Q2. What factors an! improin& technolo&ies are powerin& the recent

    rapi! rise of mobile web apps"

    'mplementation of #* (look an! feel) an! Web$+' (access to !eice)

    Q,. 'n what conte-t can a mobile browser be seen as a thin (") natie

    client" Why"

    $ mobile browser can be seen as thin as these browsers nee! little

    memory to run in an! si&ni/cantly re!uce oertheair trac makin&

    them ery suite! to be run on lowpowere! !eices when mobile

    connectiity is ba! or e-pensie or both.

    Q.

    a) Why !oes synta- nee! to be e-act" What3s the conse4uence of inali!

    synta-"

    5ynta- nee!s to be e-act so that the co!e can be correctly e-ecute! thus

    if it isn3t then the co!e will not be e-ecute!.

    b) Of the three types of pro&rammin& error which !o you think is the

    har!est to !ebu&. Why"

    he har!est error to !etect woul! be lo&ic error6 this is because neither

    the complier or run time system si&nal an error. 't3s all !own to the 4uality

    of the testin&.

    Q*. 7oolean b 6

    b 9true3 6

    What3s the problem /- it 2 ways.

    Solution 1 (need to remove quotation marks from true)

    boolean b6

    b true6

    Solution 2 (not sure if correct)

    boolean b true6

  • 7/24/2019 2081 Quiz Questions Exam

    2/15

    Q:.

    a) ;eclare a ariable to hol! the alue of total yearto!ate enrolment.

  • 7/24/2019 2081 Quiz Questions Exam

    3/15

    causes for compile time errors inclu!eKL 5ynta- errors such as missin& semicolon or use of a resere! keywor!

    (such as MclassM).L When you try an! access a ariable that is not in scope.L When you !eclare multiple obEects with the same name.

    Q10. Nsin& the strin& obEect G!o&catH twice write Eaa co!e to output the

    strin& Gcat an! !o&H to the console.

    String dogcat;

    dogcat = cat and dog;

    System.out.println(dogcat);

    Week ,

    Q1. What are the three steps re4uire! to use any $+' class that has a

    public constructor"

    i.e. classes like 5canner not like %ath

    STEP 1:

    ell the compiler where to /n! the class in the $+' library

    STEP 2:

    ?reate an obEect of the class ($A$ instantiatin& an obEect)

    STEP 3:

    $pply the class3s metho!s to the obEect to &et it to !o what you want it to

    !o

  • 7/24/2019 2081 Quiz Questions Exam

    4/15

    Q2.

    a) What !oes the import statement import" =-plain your answer

    he import statement in aa allows us to refer to classes which are!eclare! in other packa&es to be accesse! without referrin& to the fullpacka&e name.

  • 7/24/2019 2081 Quiz Questions Exam

    5/15

    b) What is the semantics (meanin&) of the operator"?hecks if the alues of two operan!s are e4ual or not if yes thencon!ition becomes true e.&. ($ 7) is not true.

    c)

  • 7/24/2019 2081 Quiz Questions Exam

    6/15

    QJ.

    a) What is a counter controlle! loop"$ countercontrolle! loop is a con!itioncontrolle! loop withpre!ictable number of iterations. he loop starts at some number

    (usually the topmost number or zero) then counts !own until itreaches the limit (usually zero or the topmost number) at whichpoint it e-its the loop. he other common type starts at zero or onean! increments until it reaches a !estination number.

    b) What repetition structure shoul! be use! for a counter controlle!

    loop"

    oop con!ition appears at be&innin& of pretest loop

    c) #ow can it become an in/nite loop"

    %ust contain a statement that makes the e-pression true!) What is a 5entinel ?ontrolle! loop"

    'n a 5entinel?ontrolle! loop a special alue calle! a sentinel alueis use! to chan&e the loop control e-pression from true to false.

    e) What repetition structure shoul! be use! for a 5entinel ?ontrolle!

    loop"""""""

    f) #ow can it become an in/nite loop"

    """"""

    Week

    Q1.

    a) When an e-ception is encountere! in the co!e in a try block what

    statement e-ecutes ne-t assumin& the e-ception is cau&ht in this

    tryT catchT/nally block" =nclose the statement(s) that coul! cause the e-ception in a try

    block ;eal with the e-ception (inclu!in& !oin& nothin&) in a catch block

    that catches the e-ception Optionally enclose any subse4uent co!e that must be performe!

    re&ar!less of whether an e-ception occurre! or not in a /nallyblock

    b) What is the relationship between e-ception han!lin& an! the call stack"c) Why !o we bother to catch e-ceptions"

  • 7/24/2019 2081 Quiz Questions Exam

    7/15

    Q2.

    a) #ow many return statements can a metho! hae if its hea!er inclu!es

    the keywor! Goi!H"

    b) #ow many return statements can a metho! hae if its hea!er !oes not

    inclu!e the keywor! Goi!H"

    c) What !oes &oo! co!in& style hae to say about the number of return

    statements a metho! shoul! hae" Why"

    Q,.

    a) $ metho! call inclu!es actual parameters. 5yntactically what can an

    actual parameter be"

    b) $ metho! !e/nition inclu!es formal parameters. 5yntactically what can

    a formal parameter be"

    c) What is the syntactical re4uirement between a metho!3s actual an!

    formal parameters"

    !) $t time of call !escribe e-actly what occurs with respect to a metho!3s

    parameters"

    e) 'f a formal parameter an! its matchin& actual parameter are both

    ariables is it si&ni/cant whether their names match or not"

    Q*.

    a) What is the scope of a local ariable"

    b) What is the scope of a formal parameter"

    c) What is the scope of a ariable !eclare! outsi!e of all metho!s"

    !) What is the lifetime of a local ariable"

    e) #ow many lifetimes can a local ariable hae"

    f) What is the relationship between these lifetimes"

    &) What is the lifetime of a formal parameter"

    Q:.

    a) aa arrays hae a /-e! size but this can be iewe! as a ma-imum size.

    #ow"

    b) =-plain how to insert an element into a Eaa array. 's anythin& lost in

    this process"

    c) =-plain how to !elete an element from a Eaa array.

    QB.

  • 7/24/2019 2081 Quiz Questions Exam

    8/15

    ;escribe what the followin& co!e !oes. ;OF3 ;=5?'7= $F< $5+=? O>

    #= ?O;=.

    Q8.

    a) When a !ebu&&er halts at a breakpoint what line of co!e will e-ecute

    ne-t"

    b) When you Gstep oerH a metho! call in the !ebu&&er is that metho!completely e-ecute!"

    c) Why use G5tep oerH"

    !) 'f you acci!ently G5tep intoH a metho! how can you recoer"

    e) '!entify three ways of /n!in& out a ariable3s alues when stoppe! at a

    breakpoint.

    QJ. $fter the followin& co!e has successfully e-ecute!Ka) What is the alue store! at int1"

    b) What is the alue store! at a1 R1S"

    c) What is the alue store! at a1 R2S"

  • 7/24/2019 2081 Quiz Questions Exam

    9/15

    Q10.

    $fter the followin& co!e has successfully e-ecute!K

    a) What is the alue of i"

    b) What is the alue of p.a&e"

    c) What is the alue of s"

  • 7/24/2019 2081 Quiz Questions Exam

    10/15

    Week *

    Q1.

    a) What is a class"

    b) #ow many obEects can be instantiate! from a class an! what is the !ata

    type of these obEects"

    c) What is the state of an obEect"

    !) What !o obEects of a class share"

    e) What is FO share! by obEects of a class"

    Q2.

  • 7/24/2019 2081 Quiz Questions Exam

    11/15

    a) =-plain how Eaa can preent access to instance ariables by co!e

    outsi!e their class"

    b) =-plain how Eaa co!ers can proi!e controlle! access to the instance

    ariables of a class"

    Q,. What are the bene/ts of encapsulatin& !ata an! the only co!e that

    can !irectly manipulate that !ata"

    Q.

    a) What is the scope of a local ariable"

    b) What is the scope of an instance ariable"

    c) What is the lifetime of a local ariable"

    !) What is the lifetime of an instance ariable"

    e) #ow can a metho! connect its lifetimes"

    Q*.

    a) What is the i!enti/erK sometin!most likely to be syntactically"

    b) What is the i!enti/erK Sometin!most likely to be syntactically"

    c) What is the i!enti/erK sometin! ()most likely to be syntactically"

    !) What is the i!enti/erK Sometin! ()most likely to be syntactically"

    Q:.

    a) #ow !oes a constructor !iDer from a normal metho! in its !eclaration"

    b) #ow !oes a constructor !iDer from a normal metho! in its inocation"

    c) #ow many constructors can a class hae"

    !) #ow many constructors shoul! a class hae"

    e) Why are constructors public"

    QB. he followin& 4uestions are about co!e written with &oo! style.

    a) 5houl! a !rier class contain instance ariables" Why"

    b) What metho!s shoul! appear in a !rier class"

    c) 5houl! a thin&Iconcept class contain instance ariables" Why"

    !) What types of metho! can appear in a thin&Iconcept class"

    #int accessors an! mutators both fall into the same type here

  • 7/24/2019 2081 Quiz Questions Exam

    12/15

    Q8. ?o!e an accessor for an instance ariable calle! wei&ht'nA&s which

    has the !ata type !ouble.

    QJ. ?o!e a mutator for an instance ariable calle! birth

  • 7/24/2019 2081 Quiz Questions Exam

    13/15

    a) ?o!e the class hea!er liner for the class 7rea! that inherits from the

    class >oo!.

    b) #ow many classes can a class inherit"

    Q:.

    a) #ow can co!e in a subclass access public ariables in a super class"

    b) #ow can co!e in a subclass access priate ariables in a super class"

    c) #ow can co!e in a subclass e-ecute public metho!s in a super class"

    !) #ow can co!e in a subclass e-ecute priate metho!s in a super class"

    e) #ow can you a!! to a super class3 !ata items an! functionality in a

    subclass"

    f) #ow can you mo!ify super class functionality in a subclass"

    QB. he keywor! GsuperH can be use! in two synta- conte-ts. What are

    they an! what is their semantics (meanin&) an! motiation (why are they

    use!)"

    Q8.

    a) What is the synta- rule an! runtime system behaiour that makes

    polymorphism possible"

    b) Why !o you think aa allows obEects of a class to be reference! by

    ariables of the class3 ancestors"

    c) Why !o you think Eaa !oes not allow obEects of a class to be reference!

    by ariables of the class3 subclasses"

    !) Why woul! you nee! to !owncast"

    QJ.

    a) #ow !oes polymorphism re!uce co!e"

    b) #ow !oes polymorphism future proof an e-istin& co!e processin&

    framework"

    Q10.

    a) What is an interface"

    b) ?o!e the class hea!er line for the class 7rea! that promises to co!e a

    metho! for each of the metho! hea!ers in the interface

    #ousehol!7u!&et'tem.

    he class =lectricity7ill also promises to co!e a metho! for each of the

    metho!s hea!ers in this interface.

  • 7/24/2019 2081 Quiz Questions Exam

    14/15

    c) #ow many interface promises can a class make"

    !) #ow !o interfaces support polymorphism" ( 't3s a similar way to the

    way inheritance !oes it)

    Week B

    Q1.

    a) Why !oesn3t $n!roi! use 5win&I$W" Yie an =-ample

    b) With respect to swin&I$W what !o heaywei&ht an! li&htwei&ht mean"

    c) Why when Eaa YN' interface becomes unresponsie is the win!ow it3s

    in not necessarily unresponsie"

    !) ;oes swin& completely replace $W" =-plain your answer.

    Q2.

    a) #ow many listener classes can react to the same eent obEect"

    b) #ow many !iDerent een obEect types can a listener class react to"

    c) #ow many responses can a listener class hae to any &ien eent

    obEects"

    Q,.

    a) What type of class are eent han!lers co!e! in" What !oes the co!e

    they contain !o"

    b) Why are se4uencin& !epen!encies between eent han!lin& metho!s a

    problem in YN'Ieent !rien co!e"

    c) ?an you think of a way aroun! the se4uencin& !epen!ency problem

    when it cannot be aoi!e!" hink about your own e-perience with

    YN'I=ent !rien interfaces. (#'FK what happens if you try to leae wor!

    without sain& it")

    Q. #ow are eent han!lers that we co!e callable from $+' co!e"

    Q*.

    a) When !oes an instantiate! >rame instance !ie"

    b) When you close the >rame instance /rstWin!ow (see below) what

    happens" What !oesn3t happen"

    c) 5o why is the followin& problematic in a sin&le win!ow application"

  • 7/24/2019 2081 Quiz Questions Exam

    15/15

    FirstWindow. setDefaultCloseperation(!Frame."#D$%&%C'S$) ;

    Q:. Our /rst attempt at a YN'Ieent !rien pro&ram was written usin& Eust

    two custom classes. his was 4uickly rewritten usin& three custom

    classes. 7rieXy !escribe the role of each of these , classes.

    QB. With respect to the followin& co!eK

    endutton.addction'istener(new ction'istener () *

    pu+lic ,oid action-erformed (ction$,ent e) *

    System.eit(/) ; 00 eit normally1

    1);

    a) What syntactically entity !oes the trailin& G6H terminate"

    b) What syntactically entity !oes the trailin& G)H terminate"

    c) What syntactically entity !oes the trailin& GZH terminate"

    Q8. =-plain the eDect of the co!e in QB. (;O FO ;=5?'7= #= ?O;=UU)

    QJ. ewrite the co!e in QB to use a name! listener class

    (=n!7utton?lickistener) that is instantiate! in situ (in place)"

    Q10.

    a) #ow !oes threa!in& stimulate parallel processin&"

    b) Why !o you think threa!in& is important in YN'Ieent !rien

    pro&rammin&"

    c) ;escribe how to create an! run a new threa!.

    !) What is the co!e you want to run in the new threa! re4uires inheritance

    from some other class"