Oops 2 Marks and 16 Marks

Embed Size (px)

Citation preview

  • 8/13/2019 Oops 2 Marks and 16 Marks

    1/72

    2 Marks and 16 Marks

    Class : III EEE

    Subject Code : CS2311

    Subject : Object Oriented Programming

    Part-A

    1) Gi e t!e e olutiononce"tdiagram# o$ OOPS c

    Machine language

    Procedure language

    Assembly language

    OOPS

    2) %e$ine &ecursion'

    Recursion is the process of defining somethin allows a method to call itself recursi!eAmethod" that

    int fact#int n$%

    int result&

    if #n' '1$ return 1&

    result'(1$ fact#n)n&

    return result&

    *

    3) (!at is Procedure oriented language'

    +on!entional programming (le!ellang usingage suchhigh as +O,O- commonlyknownorientedasProcedurelanguage #POP$" .n POP written to accomplish the tasks such as readi

  • 8/13/2019 Oops 2 Marks and 16 Marks

    2/72

    ) Gi e some c!aracteristics-orientedlanguageo$"rocedure#

    / 0mphasis is on doing things #algorithms$" / -argerareprogramsdi!ided into smaller programs kno / Most of

    the functions share global data"

    / ata mo!e openly around the system from fun / 0mploys top-down approach in program design" unction

    1 unction(2 unction(3

    unction(4ction(5 unction(6 unction(

    unction(7 Main program

    *) (rite an+ $our $eatures o$ OOPS#

    / 0mphasis is on data rather than on procedur / Programs are di!ided into ob8ects"

    / ata is hidden and cannot be accessed by e9 / ollows bottom -upapproach in program design"

    ,) (!at are t!e basic conce"ts o$ OOS'

    / Ob8ects"

    / +lasses"

    / ata abstraction and 0ncapsulation" / .nheritance"

    / Polymorphism"

    / ynamic binding" / Message passing"

  • 8/13/2019 Oops 2 Marks and 16 Marks

    3/72

    ) (!at are objects'

    Ob8ects are(timebasentitieincrunan(orientedob8ect system" :hey may place a bank account a table of data orany the data and code to manipulate the data and

    .)(!atis a class'

    :he entire set of data and(definedcodeofdataan ob8ecttypewi a class" Once a class has been defined we caclasses" +lasses(definedaredataa!eustypesrlike(in andtypesbuiltbehof the pro language"

    /) (!at is enca"sulation'

    ;rapping up of data and function within the s

    10)(!at is data abstraction'

    :he insulation of data fromed directasdataoraccessinformatiohidingby binding" :he data is not accessible to theou wrapped in the class can access it"

    11)(!at are data members and member $unctions

    +lasses use the conceptdefinedof ab s tractionlistofandabstar weight and cost and uses functions to opecalled as data members because they hold info areledcalas methods or member functions"

    0g< int a b& == a b are data members

    >oid getdata # $ & == member function

    12)(!at is d+namic binding or late binding'

    ,inding refers to the linking of a procedure ynamic binding means that the code associated the time of(t imehe"call at the run

    13)(rite t!e "rocess o$-oriented"rogrammilanguage'inan obj

    / +reate classes that define ob8ects and thei

    /+reating ob8ects from class definition"

  • 8/13/2019 Oops 2 Marks and 16 Marks

    4/72

    / 0stablishing communication among ob8ects"

    1 )Gi e an+ $our ad antages o$ OOPS#

    :he principle of data hiding helps the pro be in!aded by code amin" other parts of the p .t is poss

    ha!e (multiplee9istwithoutinsancesa

    ? Ob8ect oriented programming can be easily? Software comple9ity can be easily managed"

    1*)(!at are t!e$or$eaturbasedobj-ct re uired"rogramming anguag

    / ata encapsulation"

    / ata hiding and access mechanisms"

    / Automatic initiali@ation and clear up of ob

    / Operator o!erloading"

    1,)(!at are t!e $eatures re uired $or object

    / ata tionencapsula"

    / ata hiding and access mechanisms"

    / Automatic initiali@ation and clear up of ob / Operator o!erloading"

    / .nheritance"

    / ynamic binding"

    1 )Gi e an+ $our a""lications o$ OOPS

    Real(time systems"

    Simulation and modeling"

    Ob8ect(oriented databases"

    A. and e9pert systems"

  • 8/13/2019 Oops 2 Marks and 16 Marks

    5/72

    1.) Gi e an+ $our a""lications o$ c '

    / Since cBB allows(relatedusto ob8ects createhierarchywe(orientedcanbuil libraries which can be used later bymany pr

    / +BB are easilyableandmaintaine9pandable"

    / + part of +BB gi!es the language(le!el thedetailsabilit"

    / .t is e9pected that(purpose+BBwill anguagereplace in+ asthea

    1/) (!at are to4ens'

    :he smallest indi!idualprogramareunitsknowinfollowingastokenstoke"+

    o Ceyword

    o .dentifiers

    o +onstants

    o Strings

    o Operator

    20)(!at are 4e+5ords'

    :he keywords implement specific +BB language and cannotas namebeu s edfro the program !ariables or

    0g< go to .f struct else union etc"

    21) &ules $or naming t!e identi$iers in C #

    / Only alphabetic characters digits and unde / :he name cannothdigis tart" wit

    / :he upper case and lower case letters are d / A declared keyword cannot be used as a !ari

    22)(!at are t!e o"erators a ailable in C '

    All operators in + are also used in on+BB" .n a operator DD the other new operators in +BB ar

  • 8/13/2019 Oops 2 Marks and 16 Marks

    6/72

    Scope resolution operator

    < < )(to(Pointermember declarator

    (D) Pointer(to(member operator

    ") Pointer(to(member operator

    delete Memory release operator endl -ine feed operator

    new Memory allocationator oper setw ield width operator

    23)(!at is a sco"e resolution o"erator'

    Scope resolution operator is used to unco!er !ersion of !ariables"

    0goid show#$%

    System"out"println#TSuper classH$

    *

    class , e9tends A%

    "

    >oid show#$%

    System"out"println#Tsub classH$

    *

    class o!erride%

    , sub ' new ,# $&

    Sub" show# $&

    *

    11 )%e$ine %+namic 7et!od %is"atc!'

    ynamic Method ispatch is therriddenmechanismfunctionbyw resol!ed at run time rather than compile timmeans of ynamic Method ispatch"

    Principle< A super class reference !ariable c resol!e!erriddencallsto methods at run time" when ah

  • 8/13/2019 Oops 2 Marks and 16 Marks

    41/72

    super class reference 8a!a determines which type of the ob8ect being referredthetob8ecat thebeit referred determines which !ersion of

    11.)(!at are t!e uses o$ $inal 4e+5ord'

    1" to create the eKui!alent of named constant

    2" :o Pre!ent o!erriding

    3" :o pre!ent inheritance"

    11/)?o5e$ineto da Pac4age'

    .nclude package statement as the first statem defines a name space in which classes are sto

    S+nta

  • 8/13/2019 Oops 2 Marks and 16 Marks

    42/72

    dot"

    121)(ritedo5n t!e s+nta $or de$ining Inter$ace'

    An interface is defined similar to a class

    S+nta

  • 8/13/2019 Oops 2 Marks and 16 Marks

    43/72

    A 8a!a e9ceptiondescribesisan ob8ectane9ceptionalthat condit of code" ;hen an e9ceptional condition arisesthrown in the method that caused error"

    ^a!a 09ception handling s

  • 8/13/2019 Oops 2 Marks and 16 Marks

    44/72

    7et!od 7eaning

    getJame Obtain a threadXs name getPriority Obtain a threadXs priority isAli!e eterminenningif a

    thread is still ru 8oin wait for a thread to terminate

    run 0ntry point for the thread

    sleep Suspend a thread for a period of time"

    12,)(!at are t!e t5o 5a+s $or creating a ;!re,y implementing the runnable interface"

    +lass Jewthread implements Runnable

    ,y 09tendingthe :hread class

    +lass Jewthread e9tends :hread

    Part-F

    1#(!at are t!e Deatures o$ Oo" s !o5 are t!

    Ob8ects"

    +lasses"ata abstraction and 0ncapsulation"

    .nheritance"

    Polymorphism"

  • 8/13/2019 Oops 2 Marks and 16 Marks

    45/72

    ynamic binding"

    Messageing"pass

    2# E "lain about inline $unction'

    An inline function is a function thatcompilerise9pa replaces the function call with the correspon as

    Inline function(header

    %

    function body

    *

    :he situations where inline e9pansion may not

    for functions returning s5itc!> or goto ae9ists!alues if loop a

    for functions not returning !alues if a re

    if funcstatic ion!ariablescontain

    finlinefunctions are recursi!e

    3# E "lain Dunction O erloading'

    unction o!erloading means we can use the sam a !ariety of different tasks"

    0g< An o!erloaded add # $ asfunctionshown belowhandles" di

    = eclarations

    i!" int add# int a int b$& ==add function wi

    !" int add# int a int b int c$& ==add funct

    !i" double add# int p double K$& ==add funct

  • 8/13/2019 Oops 2 Marks and 16 Marks

    46/72

    different type == unction calls

    i" add #3 4$&

    ii" add #3 4 5$&

    iii" add #3 1G"G$&

    # E "lain about O"erator O erloading'

    +BB has the ability to pro!ide the operators mechanism of gi!ings tosuchan soperatorcialmeaniisknowng as pro!ides a fle9ible option for the creation o

    :he operators that cannot be o!erloaded are"

    +lass member access operator #" ")$

    Scope resolution operator #

  • 8/13/2019 Oops 2 Marks and 16 Marks

    47/72

    the function name" :he rules for Operator o!e

    Only the e9isting operators can be o!erload

    :he o!erloaded operatorthatmustis ha!eofuserat least defined data type"

    :he basic meaning of the operator should no

    O!erloaded operators follow the synta9 rule :hey cannot be o!erridden"

    *# E "lain o erloading nar+ Finar+ o"erato

    ;hen unaope r yators are o!erloaded using member fu return no e9plicit !alues"

    ;hen binary operators are o!erloaded using me Also the left hand sideftheoperandrele!antmustclassbean" ob

    ;hen unary operators are o!erloaded using fri #ob8ect of the rele!ant class$

    ;hen binary operators are o!erloaded using fr operatorin!okedcanbeusing member functions as follo

    .n case of Lnary operators o!erloaded operat ob8ect/name op

    .n case of binary operators it would be in!o

    Ob8ect " operator op#y$

    where op is the do!erloadedyisthe argumentoperator" an

    :he o!erloaded operator can be in!oked using

    .n case of unary operators o!erloaded operat

    Operator op #9$&

    .n case of binary operators o!erloaded opera

  • 8/13/2019 Oops 2 Marks and 16 Marks

    48/72

    Operator op #9 y$

    :he operators that cannot be o!erloaded using

    Assignment operator '

    unction call operator # $

    Subscripting operator N

    +lass member access operator Z

    ,# E "lain about ;+"e con ersions'

    :he three types of data con!ersion are

    i"n!ersion+o from basic type to class type"

    ii" +on!ersion from class type to basic type"

    iii" +on!ersion from one class type to anothe A casting operator is a function that satisfi

    .t must be a class member"

    .tnotmustspecify a return type"

    .t must not ha!e any arguments"

    :he general form of o!erloaded casting operat operator type name # $

    %

    "" == function statements

    *

    .t is also known as con!ersion function"

    i" ,asic to class type con!ersion

  • 8/13/2019 Oops 2 Marks and 16 Marks

    49/72

    +on!e r sionombasicf data type to class type can be does it" +onstructor takes a single argument

    0g< +on!erting int type to class type

    class time

    %

    int hrs mins&

    public