CS304 Object-Oriented Programming Final Exam
45 Questions
7 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 of the following causes run time binding?

  • Declaring object of abstract class
  • Declaring overridden methods as non-virtual (correct)
  • Declaring pointer of abstract class
  • None of the given

Which of the following is the best approach if it is required to have more than one functions having exactly same functionality and implemented on different data types?

  • Templates (correct)
  • Overloading
  • Encapsulation
  • Data hiding

A copy constructor is invoked when

  • a function returns by reference.
  • a function do not returns by value.
  • an argument is passed by reference.
  • an argument is passed by value. (correct)

Like template functions, a class template may not handle all the types successfully.

<p>True (A)</p> Signup and view all the answers

A class template may inherit from another class template.

<p>True (A)</p> Signup and view all the answers

By default the vector data items are initialized to ________.

<p>0.0 (A), 0 (C)</p> Signup and view all the answers

In private ______ only member functions and friend classes or functions of a derived class can convert pointer or reference of derived object to that of parent object.

<p>inheritance (C)</p> Signup and view all the answers

Which one of the following terms must relate to polymorphism?

<p>Dynamic binding (C)</p> Signup and view all the answers

By default the vector data items are initialized to

<p>0 (B), 0.0 (D)</p> Signup and view all the answers

A function template can not be overloaded by another function template.

<p>True (A)</p> Signup and view all the answers

Which of the following is the best approach to implement generic algorithms with minimum number of coding lines?

<p>Templates (D)</p> Signup and view all the answers

Identify the correct way of declaring an object of user defined template class A for char type members?

<p>A<char> obj; (A)</p> Signup and view all the answers

The user must define the operation of the copy constructor.

<p>True (A)</p> Signup and view all the answers

Default constructor is such constructor which either has no ---------or if it has some parameters these have -------- values

<p>Parameter, default (A)</p> Signup and view all the answers

The type that is used to declare a reference or pointer is called its

<p>static type (C)</p> Signup and view all the answers

How the information hidden within an object can be accessed?

<p>Through both public and private members (A)</p> Signup and view all the answers

The sub-object's life is not dependant on the life of master class in

<p>Aggregation (C)</p> Signup and view all the answers

Encapsulation means

<p>Data and behaviour are tightly coupled within an entity (B)</p> Signup and view all the answers

Algorithms can only be implemented using STL containers.

<p>False (B)</p> Signup and view all the answers

When we write a class template the first line must be:

<p>template &lt;class T &gt; (B)</p> Signup and view all the answers

An STL container can not be used to,

<p>compile c++ programs. (A)</p> Signup and view all the answers

Consider a class named Vehicle, which of the following can be the instance of class Vehicle?

<p>1, 5, 6 (B)</p> Signup and view all the answers

Associativity can be changed in operator overloading.

<p>False (B)</p> Signup and view all the answers

A normal C++ operator that acts in special ways on newly defined data types is said to be

<p>overloaded (B)</p> Signup and view all the answers

Which operator can not be overloaded?

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

Suppose obj1 and obj2 are two objects of a user defined class A. An + operator is overloaded to add obj1 and obj2 using the function call obj1+obj2. Identify the correct function prototype against the given call?

<p>A operator + ( A &amp;obj); (B)</p> Signup and view all the answers

Public methods of base class can --------be accessed in its derived class

<p>directly (C)</p> Signup and view all the answers

If there is a pointer p to objects of a base class, and it contains the address of an object of a derived class, and both classes contain a nonvirtual member function, ding(), then the statement p->ding(); will cause the version of ding() in the ______ class to be executed.

<p>Base (A)</p> Signup and view all the answers

When the base class and the derived class have a member function with the same name, you must be more specific which function you want to call (using ______ ).

<p>scope resolution operator (D)</p> Signup and view all the answers

Non Template Friend functions of a class are friends of ______ instance/s of that class.

<p>All (C)</p> Signup and view all the answers

In Private only member functions and friend classes or functions of a derived class can convert pointer or reference of derived object to that of parent object

<p>inheritance (D)</p> Signup and view all the answers

In order to define a class template, the first line of definition must be:

<p>template &lt;typename T&gt; (D)</p> Signup and view all the answers

In case of multiple inheritance a derived class inherits,

<p>Both public data members and member functions of all its base classes (B)</p> Signup and view all the answers

Which of the following is incorrect line regarding function template?

<p>Class&lt;template T&gt; (B)</p> Signup and view all the answers

Which of the following is/are advantage[s] of generic programming?

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

Which one of the following functions returns the total number of elements in a vector.

<p>size() (D)</p> Signup and view all the answers

Assume a class Derv that is privately derived from class Base. An object of class Derv located in main() can access

<p>public members of Derv. (C)</p> Signup and view all the answers

Each try block can have __ no. of catch blocks.

<p>As many as necessary. (C)</p> Signup and view all the answers

Two important STL associative containers are __ and __

<p>set,map (C)</p> Signup and view all the answers

The mechanism of selecting function at run time according to the nature of calling object is called,

<p>late binding (B)</p> Signup and view all the answers

An abstract class is useful when

<p>We do not want to instantiate its object. (B)</p> Signup and view all the answers

Public methods of base class can __ be accessed in its derived class

<p>directly (C)</p> Signup and view all the answers

Multiple inheritance can be of type___

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

When a subclass specifies an alternative definition for an attribute or method of its superclass, it is __ definition in the superclass.

<p>overriding (D)</p> Signup and view all the answers

A function call is resolved at run-time in___

<p>virtual member function. (D)</p> Signup and view all the answers

Flashcards

Dynamic Binding

The process of selecting the correct function to execute at runtime based on the type of object being referenced. This allows for flexibility in handling different object types with the same function call.

Abstract Class

A class that defines a general interface but leaves some of its methods undefined. Abstract classes cannot be instantiated, they serve as templates for concrete derived classes.

Inheritance

The mechanism by which a derived class inherits attributes and methods from its base class. This promotes code reuse and promotes a hierarchical relationship.

Function Template

The process of creating a function that can work with different data types by specifying a placeholder for the data type. This promotes code reusability and flexibility.

Signup and view all the flashcards

Template Specialization

A specialized version of a template that handles a specific data type. It allows for fine-grained control over template behavior for certain types.

Signup and view all the flashcards

Copy Constructor

A special constructor that initializes a new object with the values from an existing object of the same class. This is often used to copy the state of the existing object to the new one.

Signup and view all the flashcards

Composition

An object that provides access to the functionalities of an existing object. This is used to avoid directly exposing the original object's internal details.

Signup and view all the flashcards

Base Class Pointer

A pointer that can point to objects of a derived class or any of its base classes. This is used to access objects polymorphically through a common base class pointer.

Signup and view all the flashcards

Virtual Function

A function declared in a base class that may be overridden in derived classes. It allows for polymorphic behavior where the actual function executed is determined at runtime based on the object type.

Signup and view all the flashcards

Generic Programming

A mechanism for creating reusable code that can handle different data types. It allows for code to be written once and used with various data types without needing to rewrite the code for each type.

Signup and view all the flashcards

Static Binding

The mechanism of binding a function call to its implementation at compile time. This means the function to be executed is determined before the program runs, offering efficient and predictable performance.

Signup and view all the flashcards

Non-Virtual Function

A member function that does not rely on the type of object it is called on. The same function code is executed regardless of the object's type.

Signup and view all the flashcards

Non-Overridable Function

A type of function that has its implementation defined in the class where it is declared. These functions cannot be overridden in derived classes.

Signup and view all the flashcards

Function Pointer

A pointer to a function that can be assigned to any function with the same signature. This allows different functions to be used interchangeably, providing flexibility in function calls.

Signup and view all the flashcards

Partial Template Specialization

The process of customizing a template instantiation for a specific data type. It allows for specialized behavior for particular types that may not be handled well by the general template.

Signup and view all the flashcards

Constructor

A constructor that is automatically called when an object is created, providing an initial state for that object. It can take parameters or be parameterless.

Signup and view all the flashcards

Destructor

A function that is automatically called when an object goes out of scope. It is used to release resources, perform cleanup tasks, or ensure a consistent state before an object's destructor.

Signup and view all the flashcards

Overloading

The mechanism of selecting the correct member function to execute at compile time, based on the types of arguments provided. This is used for functions with the same name but different parameter lists.

Signup and view all the flashcards

Throwing Function

A function that throws an exception when an error condition is detected. This function signals that an error has occurred and allows for error handling code to be executed.

Signup and view all the flashcards

Catch Block

A block of code that executes when an exception is thrown. This block is used to handle the exception and take appropriate action.

Signup and view all the flashcards

Throws Keyword

A keyword used to indicate that a function can throw an exception. This helps to ensure that the function is used responsibly and that appropriate exception handling is in place.

Signup and view all the flashcards

Finally Block

A construct that allows for the execution of code regardless of whether an exception was thrown or not. This block ensures that certain actions, like cleanup tasks, are always performed before the try-catch block ends.

Signup and view all the flashcards

Public Inheritance

A type of inheritance where the derived class can access all members (public, protected, and private) of the base class. This is a rare inheritance type because it grants full access to the base class's internal data.

Signup and view all the flashcards

Protected Inheritance

A type of inheritance where the derived class can access only the public and protected members of the base class. This is a common inheritance type, and it allows for controlled access to the base class's members.

Signup and view all the flashcards

Private Inheritance

A type of inheritance where the derived class can only access the public members of the base class. Private and protected members are not available. This type of inheritance restricts access to the base class's members and should be used when you need to access only publicly available features.

Signup and view all the flashcards

Private Derivation

A special type of inheritance where the derived class does not inherit members from the base class, but it can access the members of the base class via its private or protected members. This is useful for reusing the existing implementation of the base class without inheritance, for example, when you want to implement the same interface but with different internal code.

Signup and view all the flashcards

Object

An object of a class that contains all the data and operations needed to represent a single instance of the class. Objects are created from the blueprint defined by the class.

Signup and view all the flashcards

Class

A mechanism to define a specific grouping of related objects, attributes, and operations that represent a concept or entity. A class acts as a blueprint for creating objects.

Signup and view all the flashcards

Collection

A collection of objects that share a common structure (attributes) and behavior (methods). It acts as a container to organize related objects with shared characteristics.

Signup and view all the flashcards

Method

An operation that is performed on an object. Methods are defined within a class and act as functions that manipulate the object's attributes or perform actions.

Signup and view all the flashcards

Attribute

A data value associated with an object, representing a specific characteristic or state of the object. Attributes are essentially variables that store information about the object.

Signup and view all the flashcards

Study Notes

CS304 Object-Oriented Programming Final Exam

  • Question 1 (Marks: 1): Which of the following causes run-time binding?

    • Declaring an object of an abstract class
    • Declaring a pointer of an abstract class
    • Declaring overridden methods as non-virtual
    • None of the given
  • Question 2 (Marks: 1): Which of the following is the best approach if it is required to have more than one function with the same functionality implemented on different data types?

    • Templates
    • Overloading
    • Data hiding
    • Encapsulation
  • Question 3 (Marks: 1): When is a copy constructor invoked?

    • A function does not return by value
    • An argument is passed by value
    • A function returns by reference
    • An argument is passed by reference
  • Question 4 (Marks: 1): Can a class template not handle all the types successfully?

    • True
    • False
  • Question 6 (Marks: 1): Can a class template inherit from another class template?

    • True
    • False
  • Question 7 (Marks: 1): By default, what value are vector data items initialized to?

    • 0
    • 0.0
    • 1
    • null
  • Question 8 (Marks: 1): In Private, derived classes can convert parent pointers?

    • specialization
    • inheritance
    • abstraction
    • composition
  • Question 9 (Marks: 1): Which is/are an advantage(s) of generic programming?

    • Reusability
    • Writability
    • Maintainability
    • All of the given
  • Question 10 (Marks: 1): What do template functions use compared to ordinary functions?

    • Greater Memory
    • Lesser Memory
    • Equal Memory
    • None of the given options
  • Question 11 (Marks: 1): Which are friends of non-template friend functions?

    • All instances
    • One specific instance
    • All instances of one type of data
    • None of the given options
  • Question 12 (Marks: 1): When is a copy constructor invoked?

    • A function does not return a value
    • An argument is passed by value
    • A function returns by reference
    • An argument is passed by reference
  • Question 13 (Marks: 1): Can a pointer to a base class point to objects of a derived class?

    • True
    • False
  • Question 14 (Marks: 1): What keyword precedes a template argument?

    • vector
    • class
    • template
    • type*
  • Question 15 (Marks: 1): Which term relates to polymorphism?

    • Static allocation
    • Static typing
    • Dynamic binding
    • Dynamic allocation
  • Question 16 (Marks: 1): Which of the following is a multiple inheritance type?

    • Public
    • Private
    • Protected
    • All of the given
  • Question 17 (Marks: 1): If a class is privately derived from another class, which members of the derived class can be accessed from main?

    • Public members of the derived class
    • Protected members of the derived class
    • Private members of the derived class
    • Protected members of the base class
  • Question 18 (Marks : 1 ): When is a copy constructor invoked?

    • A function doesn't return by value
    • An argument is passed by value
    • A function returns by reference
    • An argument is passed by reference
  • Question 19 (Marks: 1): When does a function call resolve in runtime?

    • Non-virtual member function
    • Virtual member function
    • Both non-virtual and virtual member functions
    • None of the given
  • Question 20 (Marks: 1): What are two important STL associative containers?

    • set, map
    • sequence, mapping
    • setmet, multiple
    • sit, mat
  • Question 21 (Marks: 1): When is an abstract class useful?

    • We don't derive any class from it
    • There are multiple paths from one derived class to another
    • We don't want to instantiate an object
    • You want to defer the declaration of the class
  • Question 22 (Marks: 1): Which of the following is an advantage of generic programming?

    • Reusability
    • Writability
    • Maintainability
    • All of the given
  • Question 23 (Marks: 1): What is the default initialization value of vector data items?

    • 0
    • 0.0
    • 1
    • null
  • Question 24 (Marks: 1): Which of the following are advantages of generic programming?

    • Reusability
    • Writability
    • Maintainability
    • All of the given
  • Question 25 (Marks: 1): What are the default initial values of vectors?

    • 0
    • 0.0
    • 1
    • null
  • Question 26 (Marks: 1): CS304- Object Oriented Programming (Session - 3)

  • Question 27 (Marks: 1): How to declare template class as a friend?

  • Question 28(Marks: 1): TwoDimensionalShape and ThreeDimensionalShape vs Sphere and Cube

    • True
    • False
  • Question 29 (Marks: 1): How to define a class template definition?

  • Question 30(Marks: 1): What does a derived class inherit in multiple inheritance?

  • Question 31 (Marks: 1): In private inheritance, the derived class can convert…

  • Question 32 (Marks: 1): Which is best approach if functions have same functionality but different types?

  • Question 33 (Marks: 1): What is the benefit of a subclass defining its own sub-classes instead of just its super-classes method?

  • Question 34 (Marks: 1): How many catch blocks can accommodate a single try block?

  • Question 35 (Marks: 1): What is the graphical representation of objects and classes named?

  • Question 36 (Marks: 1) Destructor function overloading:

    • True
    • False
  • Question 37 (Marks: 1): What is the behavior of a pointer to a base class that points to an object of a derived class regarding member function calls?

  • Question 38 (Marks: 1): Which operator cannot be overloaded ?

  • Question 39 (Marks: 1): Which of the following may not be an integral part of an object?

  • Question 40 (Marks:1): What is late binding?

  • Question 41 (Marks: 1): What is static binding?

  • Question 42 (Marks: 1): What is the role of a virtual function?

  • Question 43 (Marks: 1): How is an abstract class usefull?

  • Question 44 (Marks: 1): What is the advantage of having a template functions

  • Question 45 (Marks: 1): How many catch blocks can accommodate a single try block?

  • Question 46 (Marks : 1 ): How the information hidden within an object can be accessed?

Studying That Suits You

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

Quiz Team

Related Documents

Description

Test your knowledge with this final exam for CS304 on Object-Oriented Programming. This quiz covers key concepts such as templates, run-time binding, and copy constructors. Prepare to evaluate your understanding of OOP principles and practices.

More Like This

Use Quizgecko on...
Browser
Browser