cs304-midterm solved mcqs with refrences by moaaz_formatted

Upload: hahashim

Post on 02-Jun-2018

296 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/10/2019 Cs304-Midterm Solved Mcqs With Refrences by Moaaz_formatted

    1/26

    CS304- Object Oriented Programming

    Nov 07,2011LATEST SOLVED MCQS FROMMIDTERM PAPERS

    MIDTERM EXAMINATIONSpring 2010Q1( Marks: 1 ) - Please choose one

    Which part of an object exhibits its state?

    A. DataB. OperationsC. Any public partD. Any private part

    Answer:

    Q2( Marks: 1 ) - Please choose oneInheritance is a way to

    A. organize data.B. pass arguments to objects of classes.C. add features to existing classes without rewriting them.D. improve data-hiding and encapsulation.

    Answer:

    Q3( Marks: 1 ) - Please choose oneSuppose you have been given the following design,"A person has a name, age, address and sex. You are designing a class to represent a type of person

    called a patient. This kind of person may be given a diagnosis, have a spouse and may be alive". Giventhat the person class has already been created, what of the following would be appropriate to includewhen you design the patient class?

    A. registration date and diagnosisB. age and sexC. sex and diagnosisD. diagnosis and age

  • 8/10/2019 Cs304-Midterm Solved Mcqs With Refrences by Moaaz_formatted

    2/26

    Answer:

    Q4( Marks: 1 ) - Please choose oneWhat problem(s) may occur when we copy objects without using deep copy constructor?

    A. Dangling pointerB. Memory LeakageC. All of the givenD. System crash

    Answer:

    Q5( Marks: 1 ) - Please choose one

    this pointers are not accessible for static member functions.A. TrueB. False

    Answer:

    Q6( Marks: 1 ) - Please choose oneA static member function cannot be declared.

    A. StaticB. ImplicitC. ExplicitD. Virtual

    Answer:

    Q7( Marks: 1 ) - Please choose one

    _______ remain in memory even when all objects of a class have been destroyed.

    A. Static variablesB. Instance variable

    C. Primitive variablesD. None of given

    Answer:

    Q8( Marks: 1 ) - Please choose oneFriend functions are _____________ functions of a class.

    A. None of given

  • 8/10/2019 Cs304-Midterm Solved Mcqs With Refrences by Moaaz_formatted

    3/26

    B. object memberC. non-memberD. data member

    (Page 136)

    Answer:

    Q9( Marks: 1 ) - Please choose one

    ___________, which means if A declares B as its friend it does NOT mean that A can access private dataof B. It only means that B can access all data of A.

    A. Friendship is one way onlyB. Friendship is two way onlyC. NO Friendship between classesD. Any kind of friendship

    Answer:

    Q10( Marks: 1 ) - Please choose oneThe statement objA=objB; will cause a compiler error if the objects are of different classes.

    A. TrueB. False

    Answer:

    Q11( Marks: 1 ) - Please choose oneIdentify which of the following overloaded operator function's declaration is appropriate for the given call?

    Rational_number_1 + 2.325Where Rational_number_1 is an object of user defined class Rational_number.

    Rational_number operator+( Rational_number & obj);Rational_number operator+(double& obj);(Page 145)Rational_number operator+(Rational_number &obj, double& num);

    operator+(double& obj);

    Answer:

    Q12( Marks: 1 ) - Please choose oneWhich operator can not be overloaded?

  • 8/10/2019 Cs304-Midterm Solved Mcqs With Refrences by Moaaz_formatted

    4/26

    A. The relation operator ( >= )B. Assignment operator ( = )C. Script operator ( [] )D. Conditional operator (? : )

    (Page 141)

    Answer:

    Q13( Marks: 1 ) - Please choose oneTo convert from a user-defined class to a basic type, you would most likely use

    A. a built-in conversion operator.B. a one-argument constructor.C. an overloaded = operator.D. a conversion operator that's a member of the class.

    Answer:

    Q14( Marks: 1 ) - Please choose oneThe technique in which we visualize our programming problems according to real life's problems is called----------------

    A. structured programmingB. object oriented ProgrammingC. procedural programmingD. non of the given

    Answer:

    Q15( Marks: 1 ) - Please choose oneIn object orientated programming, a class of objects cans _____________ properties from another classof objects

    A. UtilizeB. BorrowC. InheritD. Adopt

  • 8/10/2019 Cs304-Midterm Solved Mcqs With Refrences by Moaaz_formatted

    5/26

    Answer:

    Q16( Marks: 1 ) - Please choose oneA C++ class is similar to --------------------

    A. StructureB. Header FileC. Library FileD. None of the given

    Answer:

    Q17( Marks: 1 ) - Please choose one

    What problem(s) may occur when we copy objects without using deep copy constructor?

    A. Dangling pointerB. Memory LeakageC. All of the givenD. System crash

    Answer:

    Q18( Marks: 1 ) - Please choose one

    Suppose that the Test class does not have an overloaded assignment operator. What happens when anassignment a=b; is given for two Test objects a and b?

    A. The automatic assignment operator is usedB. The copy constructor is usedC. Compiler errorD. Run-time error

    Answer:

    Q19

    ( Marks: 1 ) - Please choose one

    a'A static member function can be called, even when a class is not __________.

    A. DeclaredB. DefineC. InstantiatedD. C++ How to Program, Fifth Edition

  • 8/10/2019 Cs304-Midterm Solved Mcqs With Refrences by Moaaz_formatted

    6/26

    Called

    Answer:

    Q20( Marks: 1 ) - Please choose oneIdentify which of the following overloaded operator function's declaration is appropriate for the given

    call?Rational_number_1 + 2.325Where Rational_number_1 is an object of user defined class Rational_number.

    Rational_number operator+( Rational_number & obj);Rational_number operator+(double& obj);(Page 145)Rational_number operator+(Rational_number &obj, double& num); operator+(double& obj);

    Answer:

    Q21( Marks: 1 ) - Please choose one

    __________ provide the facility to access the data member.

    A. accesser functionB. private functionC. inline functionD. None of the given

    Answer:

    Q22( Marks: 1 ) - Please choose one

    Constant objects cannot change their state,

    A. TrueB. False

    Answer:

    Q23( Marks: 1 ) - Please choose one

  • 8/10/2019 Cs304-Midterm Solved Mcqs With Refrences by Moaaz_formatted

    7/26

    The ________ relationship indicates that an object contains other objects.

    A. None of givenB. `has-a'C. `is-a'D. `be-

    Answer:

    Q24( Marks: 1 ) - Please choose oneWhich one of the following features of OOP is used to derive a class from another?

    A. EncapsulationB. PolymorphismC. Data hidingD. Inheritance

    Answer:

    Q25( Marks: 1 ) - Please choose one

    _______ is a relationship

    A. InheritanceB. PolymarphismC. abstractionD. encapsulation

    Answer:

    Q26( Marks: 1 ) - Please choose one

    __________ satisfy the condition of polymorphismA. CarbonB. DiamondC. CoalD. all of the given

    Answer:

    Q27

  • 8/10/2019 Cs304-Midterm Solved Mcqs With Refrences by Moaaz_formatted

    8/26

    ( Marks: 1 ) - Please choose oneA generalization-specialization relation between classes are implemented using

    A. data hidingB. friend classesC. encapsulationD. inheritance

    Answer:

    Q28( Marks: 1 ) - Please choose oneThe >= operator can be overloaded.

    A. TrueB. False

    Answer:

    Q29( Marks: 1 ) - Please choose one

    In order to free the memory occupied by the object, we use -------------

    A. ConstructorB. DestructorC. Shallow CopyD. Deep Copy

    Answer:

    Q30( Marks: 1 ) - Please choose oneWhich of the following is not an example of multiple inheritances?----------

    A. MermaidB. WomanC. None of the givenD. Amphibious Vehicle

    Answer:

    Q31( Marks: 1 ) - Please choose oneStatic variable can be initialized more than once.

    A. TrueB. False

  • 8/10/2019 Cs304-Midterm Solved Mcqs With Refrences by Moaaz_formatted

    9/26

  • 8/10/2019 Cs304-Midterm Solved Mcqs With Refrences by Moaaz_formatted

    10/26

    C. Implementation independenceD. All of given options

    Answer:

    Q36( Marks: 1 ) - Please choose oneInheritance is a way to

    A. make general classes into more specific classes.B. pass arguments to objects of classes.C. improve data hiding and encapsulation.D. providing class growth through natural selection.

    Answer:

    Q37( Marks: 1 ) - Please choose oneStatic variable can be initialized more than once.

    A. TrueB. False

    Answer:

    Q38

    ( Marks: 1 ) - Please choose one

    For classes with common behavior, you can save effort by placing the common behavior in a __________.

    A. Derived ClassB. Base classC. Deprived ClassD. Named class

    Answer:

    Q39( Marks: 1 ) - Please choose oneWhich of the following are an advantage of OOP?

    A. OOP makes it easy to re-use the codeB. It provides an ability to create one user defined data type by extending the other It provides the

    facility of definingC. Abstract data types through which real world entities can be defined better.

  • 8/10/2019 Cs304-Midterm Solved Mcqs With Refrences by Moaaz_formatted

    11/26

    D. All of the given options

    Answer:

    Q40( Marks: 1 ) - Please choose oneThe >= operator can be overloaded.

    A. TrueB. False

    Answer:

    Q41( Marks: 1 ) - Please choose oneA static member function cannot be declared.

    A. StaticB. ImplicitC. ExplicitD. Virtual

    Answer:

    Q42( Marks: 1 ) - Please choose oneStatic variables act like a global variable in the context or scope of the class.

    A. TrueB. False

    Answer:

    Q43( Marks: 1 ) - Please choose oneThe compiler won't object if you overload the * operator to perform division.

    A. TrueB. False

    Answer:

  • 8/10/2019 Cs304-Midterm Solved Mcqs With Refrences by Moaaz_formatted

    12/26

    Q44( Marks: 1 ) - Please choose oneWe can use "this" pointer in the constructor in the body and even in the initialization list of any class if weare careful,

    A. TRUEB. False

    Answer:

    Q45( Marks: 1 ) - Please choose oneA C++ class is similar to --------------------

    A. StructureB. Header FileC. Library FileD. None of the given

    Answer:

    Q46( Marks: 1 ) - Please choose oneWhich operator can not be overloaded?

    A. The relation operator ( >= )B. Assignment operator ( = )C. Script operator ( [] )D. Conditional operator (? : )

    Answer:

    Q47( Marks: 1 ) - Please choose oneAn overloaded operator always requires one less argument than its number of operands.

    A. TrueB. False

    Answer:

    Q48( Marks: 1 ) - Please choose oneA generalization-specialization relation between classes are implemented using

    A. data hidingB. friend classesC. encapsulationD. inheritance

    Answer:

    Q49

  • 8/10/2019 Cs304-Midterm Solved Mcqs With Refrences by Moaaz_formatted

    13/26

    ( Marks: 1 ) - Please choose oneIn OOP a class is an example of _____

    A. Data TypeB. Abstract TypeC. User Defined TypeD. None of the given

    Answer:

    Q50( Marks: 1 ) - Please choose oneA class can be identified from a statement by -------------

    A. NounB. PronounC. VerbD. Adverb

    Answer:

    Q51( Marks: 1 ) - Please choose one

    The members of a class that can be accessed without creating the object of the class is called

    A. Private memberB. Data MemberC. Public MemberD. Static

    (How to Program page 983)

    MIDTERM EXAMINATIONSpring 2010

    Answer:Q52( Marks: 1 ) - Please choose oneSuppose there is an object of type Person, which of the following can be considered as one of itsattributes

    A. Name

  • 8/10/2019 Cs304-Midterm Solved Mcqs With Refrences by Moaaz_formatted

    14/26

    B. AgeC. Work()D. Both Name and Age

    Answer:

    Q53( Marks: 1 ) - Please choose oneWhat a derived class can add?

    A. New data membersB. New member functions and New friend functionsC. New constructors and destructorD. All of given

    Answer:

    Q54( Marks: 1 ) - Please choose one

    ________ is/are used to access information hidden within an object?

    A. InterfaceB. Private data membersC. Private member functionsD. Both public and private members

    Answer:

    Q55( Marks: 1 ) - Please choose onethis pointers are not accessible for static member functions.

    A. TrueB. False

    Answer:

    Q56( Marks: 1 ) - Please choose oneA static member function cannot be declared.

    A. StaticB. ImplicitC. Explicit

  • 8/10/2019 Cs304-Midterm Solved Mcqs With Refrences by Moaaz_formatted

    15/26

    D. Virtual

    Answer:

    Q57( Marks: 1 ) - Please choose one

    C++ compiler does not allow to dynamically allocate memory for objects

    A. FalseB. True

    Answer:

    Q58( Marks: 1 ) - Please choose oneGiven the following class

    class Base{int Age=33;

    }How you can improve above class with respect to accessing the field Age?

    Define the variable Age as privateDefine the variable Age as protectedDefine the variable Age as private and create a get method that returns it and a set method that updatesitClick here for detail

    Define the variable Age as protected and create a set method that returns it and a get method thatupdates it

    Answer:

    Q59( Marks: 1 ) - Please choose oneFriend class and friend function can be used as an alternate to each other

    A. TrueB. False

    Answer:

    Q60( Marks: 1 ) - Please choose oneWhich of the following operators always takes no argument if overloaded?

    A. /

  • 8/10/2019 Cs304-Midterm Solved Mcqs With Refrences by Moaaz_formatted

    16/26

    B. -

    C. +D. ++

    Answer:

    Q61( Marks: 1 ) - Please choose oneSuppose that the Test class does not have an overloaded assignment operator. What happens when anassignment a=b; is given for two Test objects a and b?

    A. The automatic assignment operator is usedB. The copy constructor is usedC. Compiler errorD. Run-time error

    Answer:

    Q62( Marks: 1 ) - Please choose oneAssume a class C with objects obj1, obj2, and obj3. For the statement obj3 = obj1 - obj2 to work correctly,if the overloaded - operator must

    A. take two arguments.B. return a valueC. create a named temporary object.D. take four arguments

    Answer:

    Q63( Marks: 1 ) - Please choose oneWhich operator can not be overloaded?

    A. The relation operator ( >= )B. Assignment operator ( = )C. Script operator ( [] )D. Conditional operator (? : )

    Answer:Q64( Marks: 1 ) - Please choose oneWe achieve independence of internal implementation from its external interface through-----------

    A. Encapsulation

  • 8/10/2019 Cs304-Midterm Solved Mcqs With Refrences by Moaaz_formatted

    17/26

    B. Information HidingC. AbstractionD. both encapsulation and information hiding

    Answer:

    Q65( Marks: 1 ) - Please choose oneWhich one of the following is not an object association?

    A. Simple AssocationB. InheritanceC. AggregationD. Composition

    Answer:

    Q66( Marks: 1 ) - Please choose oneWe capture the object attributes and behavior in Object Oriented programming using---------------

    A. ClassB. FunctionC. Data MembersD. Instances

    Answer:

    Q67( Marks: 1 ) - Please choose oneThe return type of a constructor is of -------------

    A. IntegerB. ChracterC. DoubleD. No type

    Answer:

    Q68( Marks: 1 ) - Please choose oneWhich one of the following terms best represents the statement given below, " Hiding details of an object

    from the other parts of a program" Obfustication.

    Data Mining.Compilation.Encapsulation

    Answer:

  • 8/10/2019 Cs304-Midterm Solved Mcqs With Refrences by Moaaz_formatted

    18/26

  • 8/10/2019 Cs304-Midterm Solved Mcqs With Refrences by Moaaz_formatted

    19/26

    A. inheritanceB. encapsulationC. structureD. array

    Answer:

    Q73( Marks: 1 ) - Please choose oneYour chief Software designer has shown you a sketch of the new Computer parts system she is about tocreate. At the top of the hierarchy is a Class called Computer and under this are two child classes. One iscalled LinuxPC and one is called WindowsPC. The main difference between the two is that one runs theLinux operating System and the other runs the Windows System (of course another difference is that oneneeds constant re-booting and the other runs reliably). Under the WindowsPC are two Sub classes onecalled Server and one Called Workstation. How might you appraise your designers work?

    Give the goahead for further design using the current scheme Ask for a re-design of the hierarchy withchanging the Operating System to a field rather than Class type Click here for detailAsk for the option of WindowsPC to be removed as it will soon be obsolete Change the hierarchy toremove the need for the superfluous Computer Class.

    Answer:

    Q74( Marks: 1 ) - Please choose oneConsider the code below,

    class Fred {

    public:Fred();

    ...};

    int main(){Fred a[10];Fred* p = new Fred[10];

    ...}Select the best option,

  • 8/10/2019 Cs304-Midterm Solved Mcqs With Refrences by Moaaz_formatted

    20/26

    Fred a[10]; calls the default constructor 09 timesFred* p = new Fred[10]; calls the default constructor 10 times Produce an errorFred a[10]; calls the default constructor 11 timesFred* p = new Fred[10]; calls the default constructor 11 times

    Fred a[10]; calls the default constructor 10 timesFred* p = new Fred[10]; calls the default constructor 10 times

    Answer:

    Q75( Marks: 1 ) - Please choose oneWhich construct is the source for the creation of an object?

    A. Destructor of the classB. New operatorC. Delete operatorD. Constructor of the class

    Answer:

    Q76( Marks: 1 ) - Please choose onethis pointers are not accessible for static member functions.

    A. TrueB. False

    Answer:

    Q77

    ( Marks: 1 ) - Please choose oneWhen a variable is define as static in a class then all object of this class,

    A. Have different copies of this variableB. Have same copy of this variableC. Can not access this variableD. None of given

    Answer:

    Q78

    ( Marks: 1 ) - Please choose one _______ remain in memory even when all objects of a class have been destroyed.

    A. Static variablesB. Instance variableC. Primitive variablesD. None of given

  • 8/10/2019 Cs304-Midterm Solved Mcqs With Refrences by Moaaz_formatted

    21/26

    Answer:

    Q79( Marks: 1 ) - Please choose oneGiven the following classclass Base{int Age=33;}

    How you can improve above class with respect to accessing the field Age? Define the variable Age asprivateDefine the variable Age as protectedDefine the variable Age as private and create a get method that returns it and a set method that updatesit Click here for detailDefine the variable Age as protected and create a set method that returns it and a get method thatupdates it

    Answer:

    Q80( Marks: 1 ) - Please choose one

    The life of sub object is not dependant on the life of master class in ___________.

    A. CompositionB. AggregationC. SeparationD. None of the given

    Answer:

    Q81( Marks: 1 ) - Please choose oneWhich one is not keyword in C++?

    A. operatorB. B_opC. constD. None of given

    Answer:Q82( Marks: 1 ) - Please choose oneThe >= operator can be overloaded.

    A. TrueB. False

    Answer:

  • 8/10/2019 Cs304-Midterm Solved Mcqs With Refrences by Moaaz_formatted

    22/26

    Q83( Marks: 1 ) - Please choose oneIdentify which of the following overloaded operator function's declaration is appropriate for the given call?Rational_number_1 + 2.325Where Rational_number_1 is an object of user defined class Rational_number.

    Rational_number operator+( Rational_number & obj);

    Rational_number operator+(double& obj);Rational_number operator+(Rational_number &obj, double& num); operator+(double& obj);

    MIDTERM EXAMINATIONSpring 2009

    Answer:

    Q84( Marks: 1 ) - Please choose oneA template provides a convenient way to make a family of

    A. variables and data members

    B. functions and classesC. classes and exceptionsD. programs and algorithms

    Answer:

    Q85( Marks: 1 ) - Please choose oneWhich one of the following terms must relate to polymorphism?

    A. Static allocation

    B. Static typingC. Dynamic bindingD. Dynamic allocation

    (How to program , page 1103) Click here for more detail

    Answer:

    Q86( Marks: 1 ) - Please choose one

  • 8/10/2019 Cs304-Midterm Solved Mcqs With Refrences by Moaaz_formatted

    23/26

    What is true about function templates?

    The compiler generates only one copy of the function templateThe compiler generates a copy of function respective to each type of data (Page 257) The compiler canonly generate copy for the int type data None of the given.

    Answer:

    Q87( Marks: 1 ) - Please choose oneWhich of the following is the best approach if it is required to have more than one functions having exactlysame functionality and implemented on different data types?

    A. TemplatesB. OverloadingC. Data hidingD. Encapsulation

    Answer:

    Q88( Marks: 1 ) - Please choose onetemplate class Vector { }

    This is an example of partial specialization.

    A. TrueB. False

    Answer:

    Q89( Marks: 1 ) - Please choose oneClasses like TwoDimensionalShape and ThreeDimensionalShape would normally be concrete, whileclasses like Sphere and Cube would normally be abstract.

    A. TrueB. False

    Answer:

    Q90( Marks: 1 ) - Please choose oneA non-virtual member function is defined in a base class and overridden in a derived class; if that function

  • 8/10/2019 Cs304-Midterm Solved Mcqs With Refrences by Moaaz_formatted

    24/26

    is called through a base-class pointer to a derived class object, the derived-class version is used.

    A. TrueB. False

    Answer:

    Q91( Marks: 1 ) - Please choose oneAssume a class Derv that is privately derived from class Base. An object of class Derv located in main()can access

    A. public members of Derv.B. protected members of Derv.C. private members of Derv.D. protected members of Base.

    Answer:

    Q92( Marks: 1 ) - Please choose oneIn order to define a class template, the first line of definition must be:

    A. template B. typename C. Template Class D. Class

    Answer:

    Q93( Marks: 1 ) - Please choose oneIf there is a pointer p to objects of a base class, and it contains the address of an object of a derivedclass, and both classes contain a nonvirtual member function, ding(), then the statement p->ding(); willcause the version of ding() in the _____ class to be executed.

    A. BaseB. DerivedC. AbstractD. virtual

    (not sure)

  • 8/10/2019 Cs304-Midterm Solved Mcqs With Refrences by Moaaz_formatted

    25/26

    Answer:

    Q94( Marks: 1 ) - Please choose oneWhen the base class and the derived class have a member function with the same name, you must bemore specific which function you want to call (using ___________).

    A. scope resolution operatorB. dot operatorC. null operatorD. Operator overloading

    Answer:

    Q95( Marks: 1 ) - Please choose oneNon Template Friend functions of a class are friends of ________instance/s of that class.

    A. AllB. One specificC. All instances of one date typeD. None of the given options

    Answer:

    Q96( Marks: 1 ) - Please choose one

    The find() algorithm

    A. finds matching sequences of elements in two containers.B. finds a container that matches a specified container.C. takes iterators as its first two arguments.D. takes container elements as its first two arguments.

    Answer:

    Q97

    ( Marks: 1 ) - Please choose one

    If you define a vector v with the default constructor, and define another vector w with a one-argumentconstructor to a size of 11, and insert 3 elements into each of these vectors with push_back(), then thesize() member function will return ______ for v and _____ for w.

    A. 11 for v and 3 for w.B. 0 for v and 0 for w.

  • 8/10/2019 Cs304-Midterm Solved Mcqs With Refrences by Moaaz_formatted

    26/26

    C. 0 for v and 3 for w.D. 3 for v and 11 for w.

    Answer:

    Q98( Marks: 1 ) - Please choose oneWhich of the following may not be an integral part of an object?

    A. StateB. BehaviorC. Protected data membersD. All of given

    (not sure)

    Answer:

    Q99( Marks: 1 ) - Please choose oneWhich is not the Advantage of inheritance?

    A. providing class growth through natural selection.B. facilitating class libraries.C. avoiding the rewriting of code.D. providing a useful conceptual framework.

    Answer: