CS304 Object Oriented Programming Midterm MCQs
46 Questions
8 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

Which part of an object exhibits its state?

  • Operations
  • Data (correct)
  • Any private part
  • Any public part
  • Inheritance is a way to

  • pass arguments to objects of classes.
  • organize data.
  • add features to existing classes without rewriting them. (correct)
  • improve data-hiding and encapsulation.
  • Suppose 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". Given that the person class has already been created, what of the following would be appropriate to include when you design the patient class?

  • sex and diagnosis
  • age and sex
  • diagnosis and age
  • registration date and diagnosis (correct)
  • What problem(s) may occur when we copy objects without using deep copy constructor?

    <p>All of the given</p> Signup and view all the answers

    This pointers are not accessible for static member functions.

    <p>True</p> Signup and view all the answers

    A static member function cannot be declared.

    <p>Explicit</p> Signup and view all the answers

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

    <p>Static variables</p> Signup and view all the answers

    Friend functions are functions of a class.

    <p>non-member</p> Signup and view all the answers

    Which means if A declares B as its friend it DOES NOT mean that A can access private data of B. It only means that B can access all data of A.

    <p>Friendship is one way only</p> Signup and view all the answers

    The statement objA=objB; will cause a compiler error if the objects are of different classes.

    <p>True</p> Signup and view all the answers

    Which operator can not be overloaded?

    <p>Conditional operator (? : )</p> Signup and view all the answers

    To convert from a user-defined class to a basic type, you would most likely use

    <p>a conversion operator that's a member of the class.</p> Signup and view all the answers

    The technique in which we visualize our programming problems according to real life's problems is called

    <p>object oriented Programming</p> Signup and view all the answers

    In object orientated programming, a class of objects can properties from another class of objects.

    <p>Inherit</p> Signup and view all the answers

    A C++ class is similar to

    <p>Structure</p> Signup and view all the answers

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

    <p>The automatic assignment operator is used</p> Signup and view all the answers

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

    <p>Instantiated</p> Signup and view all the answers

    Identify which of the following overloaded operator function's declaration is appropriate for the given call? Rational_number_1 + 2.325 Where Rational_number_1 is an object of user defined class Rational_number.

    <p>Rational_number operator+(Rational_number &amp;obj, double&amp; num);</p> Signup and view all the answers

    Provide the facility to access the data member.

    <p>accesser function</p> Signup and view all the answers

    Constant objects cannot change their state,

    <p>True</p> Signup and view all the answers

    Relationship indicates that an object contains other objects.

    <p>'has-a'</p> Signup and view all the answers

    Which one of the following features of OOP is used to derive a class from another?

    <p>Inheritance</p> Signup and view all the answers

    Is a relationship

    <p>Inheritance</p> Signup and view all the answers

    Satisfy the condition of polymorphism

    <p>all of the given</p> Signup and view all the answers

    A generalization-specialization relation between classes are implemented using

    <p>inheritance</p> Signup and view all the answers

    The >= operator can be overloaded.

    <p>True</p> Signup and view all the answers

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

    <p>Destructor</p> Signup and view all the answers

    Which of the following is not an example of multiple inheritances?

    <p>Woman</p> Signup and view all the answers

    Static variable can be initialized more than once.

    <p>False</p> Signup and view all the answers

    A generic class showing all the common attributes and a behavior of other classes represents a very important feature in OOP called

    <p>Inheritance</p> Signup and view all the answers

    We can get only one unique value which can be used by all the objects of that class by the use of,

    <p>static variables</p> Signup and view all the answers

    A member function having the same name as that of a class and a ~ sign with it is called,

    <p>Destructor</p> Signup and view all the answers

    Using encapsulation we can achieve

    <p>All of given options</p> Signup and view all the answers

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

    <p>Base class</p> Signup and view all the answers

    Which of the following are an advantage of OOP?

    <p>All of the given options</p> Signup and view all the answers

    Static variables act like a global variable in the context or scope of the class.

    <p>True</p> Signup and view all the answers

    The compiler won't object if you overload the * operator to perform division.

    <p>False</p> Signup and view all the answers

    We can use "this" pointer in the constructor in the body and even in the initialization list of any class if we are careful.

    <p>True</p> Signup and view all the answers

    An overloaded operator always requires one less argument than its number of operands.

    <p>False</p> Signup and view all the answers

    In OOP a class is an example of

    <p>User Defined Type</p> Signup and view all the answers

    A class can be identified from a statement by

    <p>Noun</p> Signup and view all the answers

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

    <p>Static</p> Signup and view all the answers

    Suppose there is an object of type Person, which of the following can be considered as one of its attributes

    <p>Both Name and Age</p> Signup and view all the answers

    What a derived class can add?

    <p>All of given</p> Signup and view all the answers

    Is/are used to access information hidden within an object?

    <p>Private member functions</p> Signup and view all the answers

    Which one of the following terms best represents the statement given below, " Hiding details of an object from the other parts of a program"

    <p>Encapsulation</p> Signup and view all the answers

    Study Notes

    CS304 - Object Oriented Programming Midterm Solved MCQs

    • Question 1 (Marks: 1): Which part of an object exhibits its state?

      • Data (Page 23)
    • Question 2 (Marks: 1): Inheritance is a way to:

      • add features to existing classes without rewriting them (Page 27)
    • Question 3 (Marks: 1): What should be included in a 'Patient' class (already having a 'Person' class)?

      • diagnosis and age
      • age and sex
      • sex and diagnosis
      • registration date and diagnosis
    • Question 4 (Marks: 1): What problem(s) occur when copying objects without a deep copy constructor?

      • Dangling pointer
      • Memory leakage
      • All of the given (Page 147)
      • System crash
    • Question 5 (Marks: 1): Are this pointers accessible for static member functions?

      • False (Page 114)
    • Question 6 (Marks: 1): Can a static member function be declared?

      • static
    • Question 7 (Marks: 1): What remains in memory even after all class objects are destroyed?

      • Static variables (Page 111)
    • Question 8 (Marks: 1): What are friend functions?

      • non-member functions of a class (Page 136)
    • Question 9 (Marks: 1): If A declares B as its friend, does A access B's private data?

      • No, only B can access A's private data.
    • Question 10 (Marks: 1): Does objA=objB; cause a compiler error with different classes?

      • True
    • Question 11 (Marks: 1): Which overloaded operator declaration is appropriate for Rational_number_1 + 2.325?

      • Rational_number operator+(Rational_number& obj);
      • Rational_number operator+(double& obj);
      • Rational_number operator+(Rational_number &obj, double& num);
      • operator+(double& obj);
    • Question 12 (Marks: 1): Which operator cannot be overloaded?

      • Conditional operator (? :) (Page 141)
    • Question 13 (Marks: 1): How do you convert from user-defined class to basic types?

      • Built-in conversion operator
    • Question 14 (Marks: 1): What is the programming technique that visualizes problems in real-world terms?

      • Object Oriented Programming (Page 9)
    • Question 15 (Marks: 1): What can classes of objects do in OOP?

      • Inherit properties from another class
    • Question 16 (Marks: 1): What is a C++ class similar to?

      • Structure
    • Question 17 (Marks: 1): What happens when a=b; where 'a' and 'b' are Test objects but the Test class lacks an overloaded assignment operator?

      • The automatic assignment operator is used.
    • Question 18 (Marks: 1): How can a class be identified in a statement?

    • Noun (Page 58)

    • Question 19 (Marks: 1): What are members that can be accessed without object creation?

      • Public members
    • Question 20 (Marks: 1): What are attributes of a Person object?

      • Name, Age
    • Question 21 (Marks: 1): What is/are used to access hidden information in an object?

      • Private data members
      • Private member functions (Page 69)
    • Question 22 (Marks: 1): Can this pointers be accessed with static member functions?

      • False (Page 14)
    • Question 23 (Marks: 1): Can a static member function be declared?

    • Yes, a static member function can be declared.

    • Question 24 (Marks: 1): Can memory dynamically be allocated to objects in C++?

      • False
    • Question 25 (Marks: 1): How can variable "Age" in class Base be accessed appropriately? -Define the variable Age as private and create a get method that returns it and a set method that updates it.

    • Question 26 (Marks: 1): What is not a keyword in C++?

    • B_op

    • operator

    • Question 27 (Marks: 1): Can the >= operator be overloaded?

      • True (Page 140)
    • Question 28 (Marks: 1): How can a sub-object's life be independent of the master class's life?

      • Composition
      • Aggregation (Page 134)
    • Question 29 (Marks: 1): What is a way to make general classes more specific in OOP?

      • Inheritance (Page 27)
    • Question 30 (Marks: 1): What is the return type of a constructor in C++ ?

      • No type
    • Question 31 (Marks: 1): What is the process for hiding object details from users?

    • Encapsulation

    • Abstraction(Page 16)

    • Question 32 (Marks: 1): What are the ways to declare a variable to be static in class?

    • Static variable keyword before the variable declaration.

    • Question 33 (Marks: 1): Should static variables be initialized more than once?

      • False (Page 107)
    • Question 34 (Marks: 1): What is the best approach to implement functions with identical behavior on different data types?

    • Templates

    • Overloading

    • Question 35 (Marks: 1): Is class Vector<char>* an example of partial specialization?

      • True (Page 281)
    • **Question 36 (Marks: 1):**Classes like TwoDimensionalShape and ThreeDimensionalShape, should they be abstract?

    • True

    • Question 37 (Marks: 1): Classes like Sphere and Cube should they be abstract?

      • True
    • Question 38 (Marks: 1): What is important in OOP for object identification?

      • State, Behavior (and other properties)
    • Question 39 (Marks: 1): A member function that has the same name as the class and a '~' followed by the name is called?

      • Destructor
    • Question 40 (Marks: 1): What is not an advantage of inheritance?

    • Avoiding code rewriting (and providing frameworks).

    • Expanding classes.

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Description

    Test your knowledge with this midterm quiz on Object Oriented Programming for CS304. It covers key concepts such as inheritance, class structures, and memory management. Answer multiple-choice questions to assess your understanding of the subject.

    More Like This

    Use Quizgecko on...
    Browser
    Browser