Object Oriented Programming Quiz

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Anima.jain18
A
Anima.jain18
Community Contributor
Quizzes Created: 1 | Total Attempts: 387
Questions: 20 | Attempts: 388

SettingsSettingsSettings
Object Oriented Programming Quiz - Quiz

.


Questions and Answers
  • 1. 

    Which of the following concepts provides facility of using object of one class inside another class?

    • A.

      Encapsulation

    • B.

      Inheritance

    • C.

      Composition

    • D.

      Abstraction

    Correct Answer
    C. Composition
    Explanation
    Composition is a concept in object-oriented programming that allows for the use of objects of one class inside another class. This means that one class can contain an instance of another class as a member variable. This allows for a strong relationship between the two classes, where the inner class is an essential part of the outer class. This concept promotes code reusability and modular design by allowing objects to be composed of other objects.

    Rate this question:

  • 2. 

    cout is a/an __________ .

    • A.

      Operator

    • B.

      Function

    • C.

      Macro

    • D.

      Object

    Correct Answer
    D. Object
    Explanation
    The correct answer is "object" because "cout" is an object in C++. It is an instance of the "ostream" class and is used to display output on the console.

    Rate this question:

  • 3. 

    Which of the following is not a type of constructor?

    • A.

      Copy constructor

    • B.

      Default constructor

    • C.

      Friend constructor

    • D.

      Parameterized constructor

    Correct Answer
    C. Friend constructor
    Explanation
    A friend constructor is not a type of constructor. In object-oriented programming, a constructor is a special method that is used to initialize objects of a class. It is called automatically when an object is created. The copy constructor creates a new object by copying the values of an existing object. The default constructor is a constructor that takes no arguments. The parameterized constructor is a constructor that takes one or more parameters. However, a friend constructor is not a recognized type of constructor.

    Rate this question:

  • 4. 

    Which of the following type of class allows only one object of it to be created?

    • A.

      Abstract

    • B.

      Virtual

    • C.

      Singleton

    • D.

      Friend

    Correct Answer
    C. Singleton
    Explanation
    A Singleton class allows only one object of it to be created. This is achieved by making the constructor of the class private, so that it cannot be accessed from outside the class. The class itself provides a static method that returns the instance of the class, and this method ensures that only one instance is created and returned. This pattern is commonly used in scenarios where there should be only one instance of a class, such as a database connection or a logger.

    Rate this question:

  • 5. 

    Which of the following concepts means determining at runtime what method to invoke?

    • A.

      Data hiding

    • B.

      Dynamic binding

    • C.

      Dynamic loading

    • D.

      Dynamic typing

    Correct Answer
    B. Dynamic binding
    Explanation
    Dynamic binding refers to the process of determining at runtime which method to invoke based on the actual type of the object. This allows for polymorphism, where different objects of different classes can be treated as objects of a common superclass and their specific methods can be called based on their actual types. Dynamic binding is an important concept in object-oriented programming as it enables flexibility and extensibility in the code.

    Rate this question:

  • 6. 

    How "Late binding" is implemented in C++?

    • A.

      Using c++ tables

    • B.

      Using virtual tables

    • C.

      Using indexed virtual table

    • D.

       using polymorphic tables

    Correct Answer
    B. Using virtual tables
    Explanation
    Late binding in C++ is implemented using virtual tables. A virtual table, also known as a vtable, is a lookup table of function pointers used to implement dynamic dispatch. When a class has virtual functions, a vtable is created for that class, which contains pointers to the virtual functions. During runtime, when a virtual function is called through a base class pointer, the vtable is used to determine the correct function to be called based on the actual object type. This allows for the implementation of polymorphism and enables late binding, where the function to be called is determined at runtime.

    Rate this question:

  • 7. 

    Which of the following operator is overloaded for object cout?

    • A.

      <<

    • B.

      >>

    • C.

      +

    • D.

      =

    Correct Answer
    A. <<
    Explanation
    The

    Rate this question:

  • 8. 

    Which of the following is the correct way of declaring a function as constant?

    • A.

      Const int ShowData(void) { /* statements */ }

    • B.

      Int const ShowData(void) { /* statements */ }

    • C.

      Int ShowData(void) const { /* statements */ }

    • D.

      Both A and B

    Correct Answer
    C. Int ShowData(void) const { /* statements */ }
    Explanation
    The correct way of declaring a function as constant is by using the "const" keyword after the closing parenthesis of the function declaration. This ensures that the function does not modify any member variables of the class in which it is defined. In this case, the correct answer is "int ShowData(void) const { /* statements */ }".

    Rate this question:

  • 9. 

    Which of the following ways are legal to access a class data member using this pointer?

    • A.

      This->x

    • B.

      This.x

    • C.

      *this.x

    • D.

      *this-x

    Correct Answer
    A. This->x
    Explanation
    The correct answer is "this->x". In C++, the "this" pointer is a special pointer that points to the object itself. By using the "->" operator, we can access the data member "x" of the current object. The "->" operator is used to access members of an object through a pointer. Therefore, "this->x" is the correct way to access a class data member using the "this" pointer.

    Rate this question:

  • 10. 

    Which of the following is correct about the statements given below?
    1. All operators can be overloaded in C++.
    2. We can change the basic meaning of an operator in C++.

    • A.

      Only 1 is true

    • B.

      Only 2 is true

    • C.

      Both 1 and 2 are true

    • D.

      Both are false

    Correct Answer
    D. Both are false
    Explanation
    In C++, not all operators can be overloaded. Some operators, such as the dot operator (.), the scope resolution operator (::), the ternary operator (?:), and the sizeof operator, cannot be overloaded. Therefore, statement 1 is false. Additionally, while operator overloading allows us to change the behavior of an operator, it does not change its basic meaning. The basic meaning of an operator remains the same, but we can define new behavior for the operator when it is used with user-defined types. Therefore, statement 2 is also false.

    Rate this question:

  • 11. 

    Which of the following are available only in the class hierarchy chain?

    • A.

      Public  data members

    • B.

      Private data member

    • C.

      Protected Data members

    • D.

      Member Function

    Correct Answer
    C. Protected Data members
    Explanation
    Protected data members are available only in the class hierarchy chain. This means that they can be accessed by the class in which they are defined, as well as by any derived classes. Protected data members are not accessible by objects of the class or by functions outside the class hierarchy chain. This access level provides a balance between the strict encapsulation of private data members and the complete accessibility of public data members.

    Rate this question:

  • 12. 

    Which of the following is not a type of inheritance?

    • A.

      Multiple

    • B.

      Multilevel

    • C.

      Distributive

    • D.

      Hierarchical

    Correct Answer
    C. Distributive
    Explanation
    Distributive inheritance is not a recognized type of inheritance in object-oriented programming. The other options listed - multiple, multilevel, and hierarchical - are all valid types of inheritance. Multiple inheritance refers to a class inheriting from multiple parent classes, multilevel inheritance refers to a class inheriting from a derived class, and hierarchical inheritance refers to a class inheriting from a single parent class. However, distributive inheritance is not a commonly used or recognized term in the context of inheritance.

    Rate this question:

  • 13. 

    What happens if the base and derived class contains definition of a function with same prototype?

    • A.

      Compiler reports an error on compilation.

    • B.

      Only base class function will get called irrespective of object.

    • C.

      Only derived class function will get called irrespective of object.

    • D.

      Base class object will call base class function and derived class object will call derived class function.

    Correct Answer
    D. Base class object will call base class function and derived class object will call derived class function.
    Explanation
    When both the base and derived classes contain a function with the same prototype, the function in the derived class overrides the function in the base class. This means that when a base class object calls the function, it will call the base class function, and when a derived class object calls the function, it will call the derived class function. This is known as function overriding.

    Rate this question:

  • 14. 

    Which of the following statements is correct in C++?

    • A.

      Classes cannot have data as protected members.

    • B.

      Structures can have functions as members.

    • C.

      Class members are public by default.

    • D.

      Structure members are private by default.

    Correct Answer
    B. Structures can have functions as members.
    Explanation
    In C++, structures can have functions as members. This is a key difference between structures and classes in C++. While both structures and classes can have data members, only structures can have functions as members. This allows for more flexibility in organizing and defining data and functions within a structure.

    Rate this question:

  • 15. 

    Which of the following access specifier is used as a default in a class definition?

    • A.

      Protected

    • B.

      Public

    • C.

      Private

    Correct Answer
    C. Private
    Explanation
    In a class definition, the access specifier that is used as a default is "private". This means that the members of the class, such as variables and methods, can only be accessed within the class itself and not from outside the class or its subclasses. It provides the highest level of encapsulation and data hiding, ensuring that the internal implementation details of the class are not exposed to other parts of the program.

    Rate this question:

  • 16. 

    What is correct about the static data member of a class?

    • A.

      A static member function can access only static data members of a class.

    • B.

      A static data member is shared among all the object of the class.

    • C.

      A static data member can be accessed directly from main().

    • D.

      A static member function can access only static data members of a class and A static data member is shared among all the object of the class.

    Correct Answer
    D. A static member function can access only static data members of a class and A static data member is shared among all the object of the class.
    Explanation
    A static member function can access only static data members of a class because static member functions do not have access to the non-static members of a class. A static data member is shared among all the objects of the class, meaning that any changes made to the static data member will be reflected in all instances of the class. This allows for the sharing of data between different objects of the same class.

    Rate this question:

  • 17. 

    Which of the following provides a reuse mechanism?

    • A.

      Abstarction

    • B.

      Inheritence

    • C.

      Dynamic Binding

    • D.

      Encapsulation

    Correct Answer
    B. Inheritence
    Explanation
    Inheritance provides a reuse mechanism in object-oriented programming. It allows a class to inherit properties and behaviors from another class, known as the parent or base class. This enables the derived class to reuse the code and functionality of the base class, reducing code duplication and promoting code reusability. Inheritance also supports the concept of polymorphism, where objects of derived classes can be treated as objects of the base class, providing flexibility and extensibility in the design of software systems.

    Rate this question:

  • 18. 

    Which of the following statement is correct?

    • A.

      Class is an instance of object.

    • B.

      Object is an instance of a class.

    • C.

      Class is an instance of data type.

    • D.

      Object is an instance of data type.

    Correct Answer
    B. Object is an instance of a class.
    Explanation
    The correct answer is "Object is an instance of a class." In object-oriented programming, a class is a blueprint for creating objects. An object is an instance of a class, meaning it is created based on the definition provided by the class. Each object created from a class has its own set of properties and behaviors defined by the class. Therefore, an object is an instance of a class.

    Rate this question:

  • 19. 

    How many types of polymorphisms are supported by C++?

    • A.

      1

    • B.

      2

    • C.

      3

    • D.

      4

    Correct Answer
    B. 2
    Explanation
    C++ supports two types of polymorphisms: compile-time polymorphism and runtime polymorphism. Compile-time polymorphism is achieved through function overloading and template specialization, where different functions or templates with the same name but different parameters or template arguments are used. Runtime polymorphism is achieved through virtual functions and inheritance, where a base class pointer can point to objects of different derived classes, allowing for dynamic dispatch of function calls based on the actual type of the object being referred to.

    Rate this question:

  • 20. 

    Which of the following is an abstract data type?

    • A.

      Int

    • B.

      Class

    • C.

      String 

    • D.

      Double

    Correct Answer
    B. Class
    Explanation
    An abstract data type is a data type that is defined by the behavior it exhibits rather than the specific implementation details. It provides a set of operations that can be performed on the data without revealing the internal representation. A class in programming languages like Java or C++ is an example of an abstract data type because it encapsulates data and functions/methods that operate on that data, providing a way to create objects and manipulate them.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • May 27, 2024
    Quiz Edited by
    ProProfs Editorial Team
  • Aug 10, 2020
    Quiz Created by
    Anima.jain18
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.