Programming Practices Using C++

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 Rabib
R
Rabib
Community Contributor
Quizzes Created: 3 | Total Attempts: 2,257
Questions: 70 | Attempts: 680

SettingsSettingsSettings
Programming Practices Using C++ - Quiz

Questions and Answers
  • 1. 

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

    • A.

      Virtual class

    • B.

      Abstract class

    • C.

      Singleton class

    • D.

      Friend class

    Correct Answer
    C. Singleton class
    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 called from outside the class. The class provides a static method that returns the instance of the class, and if an instance already exists, it returns that instance instead of creating a new one. This ensures that only one object of the class can exist at a time, making it a singleton class.

    Rate this question:

  • 2. 

    Which of the following is not a type of constructor?

    • A.

      Copy constructor

    • B.

      Friend constructor

    • C.

      Default constructor

    • D.

      Parameterized constructor

    Correct Answer
    B. Friend constructor
    Explanation
    A friend constructor is not a type of constructor. In C++, a friend function is a function that is not a member of a class but has access to the private and protected members of the class. However, constructors cannot be declared as friend functions. Therefore, a friend constructor does not exist.

    Rate this question:

  • 3. 

    Which of the following is an invalid visibility label while inheriting a class?

    • A.

      Public

    • B.

      Private

    • C.

      Protected

    • D.

      Friend

    Correct Answer
    D. Friend
    Explanation
    Friend is an invalid visibility label while inheriting a class. In object-oriented programming, friend is not a valid access specifier for inheritance. Public, private, and protected are the three valid access specifiers used to control the visibility of class members in inheritance. Friend is used to grant access to private or protected members of a class to another class or function, but it cannot be used to specify the visibility of a derived class.

    Rate this question:

  • 4. 

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

    • A.

      Class members are public by default.

    • B.

      Structure members are private by default.

    • C.

      Structures can have functions as members.

    • D.

      Classes cannot have data as protected members.

    Correct Answer
    C. Structures can have functions as members.
    Explanation
    The correct answer is "Structures can have functions as members." In C++, structures can have both data members and function members. This allows for the encapsulation of related data and functions within a single structure, making it a convenient way to organize and manipulate data. Unlike classes, which have default access specifiers for their members (private by default), structures have default access specifiers for their members (public by default). This means that all members of a structure are accessible by default, unless specified otherwise.

    Rate this question:

  • 5. 

    Which of the following provides a reuse mechanism?

    • A.

      Abstraction

    • B.

      Inheritance

    • C.

      Dynamic binding

    • D.

      Encapsulation

    Correct Answer
    B. Inheritance
    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 superclass or base class. This means that the subclass or derived class can reuse and extend the functionality of the superclass, reducing code duplication and promoting code reusability. Inheritance facilitates the creation of a hierarchical relationship between classes, where subclasses can inherit and modify the attributes and methods of the superclass, promoting code organization and modularity.

    Rate this question:

  • 6. 

    Which of the following cannot be used with the keyword virtual?

    • A.

      Class

    • B.

      Member functions

    • C.

      Constructor

    • D.

      Destructor

    Correct Answer
    C. Constructor
    Explanation
    The keyword "virtual" can be used with class, member functions, and destructor, but it cannot be used with the constructor. The reason for this is that the constructor is responsible for initializing the object and it cannot be overridden or inherited like other member functions. Therefore, it does not make sense to use the "virtual" keyword with the constructor.

    Rate this question:

  • 7. 

    Which one of the following options is correct about the statement given below?The compiler checks the type of reference in the object and not the type of object.

    • A.

      Inheritance

    • B.

      Polymorphism

    • C.

      Abstraction

    • D.

      Encapsulation

    Correct Answer
    B. PolymorpHism
    Explanation
    Polymorphism is the correct option because it allows objects of different types to be treated as objects of a common type. In the given statement, the compiler checks the type of reference (the variable or parameter) in the object rather than the type of the actual object itself. This is a key feature of polymorphism, as it allows for flexibility and dynamic behavior in object-oriented programming.

    Rate this question:

  • 8. 

    Which of the following problem causes an exception?

    • A.

      Missing semicolon in statement in main().

    • B.

      A problem in calling function.

    • C.

      A run-time error.

    • D.

      A syntax error.

    Correct Answer
    C. A run-time error.
    Explanation
    A run-time error refers to an error that occurs during the execution of a program. It can be caused by various factors such as dividing by zero, accessing an invalid memory location, or attempting to perform an operation on incompatible data types. In this case, the missing semicolon or a problem in calling a function would result in a syntax error, not a run-time error. Therefore, the correct answer is A run-time error.

    Rate this question:

  • 9. 

    Which of the following concepts is used to implement late binding?

    • A.

      Virtual function

    • B.

      Operator function

    • C.

      Const function

    • D.

      Static function

    Correct Answer
    A. Virtual function
    Explanation
    Virtual functions are used to implement late binding in object-oriented programming languages. Late binding allows the selection of the appropriate function implementation at runtime based on the actual type of the object being referred to, rather than the type of the reference. This enables polymorphism, where a single function can be used to handle objects of different classes that are derived from a common base class. By declaring a function as virtual, the derived class can provide its own implementation of the function, which will be called instead of the base class implementation when the function is invoked through a base class reference or pointer.

    Rate this question:

  • 10. 

    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 way to access a class data member using the this pointer is by using the arrow operator (->). The arrow operator is used to access the member of the object pointed to by the this pointer. In this case, the data member x is accessed using this->x. The other options, this.x, *this.x, and *this-x, are not valid ways to access a class data member using the this pointer.

    Rate this question:

  • 11. 

    Which of the following operators cannot be overloaded?

    • A.

      [ ]

    • B.

      ->

    • C.

      ?:

    • D.

      *

    Correct Answer
    C. ?:
    Explanation
    The ?: operator, also known as the ternary operator, cannot be overloaded. This operator is used for conditional expressions and it takes three operands. It evaluates a condition and returns one of two values depending on whether the condition is true or false. Since the ?: operator is built into the language and has a fixed functionality, it cannot be overloaded to change its behavior.

    Rate this question:

  • 12. 

    Which one of the following is the correct way to declare a pure virtual function?

    • A.

      Virtual void Display(void){0};

    • B.

      Virtual void Display = 0;

    • C.

      Void Display(void) = 0;

    • D.

      Virtual void Display(void) = 0;

    Correct Answer
    D. Virtual void Display(void) = 0;
    Explanation
    The correct way to declare a pure virtual function is by using the syntax "virtual void Display(void) = 0;". The keyword "virtual" indicates that the function is virtual, and the "= 0" at the end indicates that the function is pure virtual. A pure virtual function is a virtual function that has no implementation in the base class and must be overridden in the derived classes.

    Rate this question:

  • 13. 

    Which of the following correctly describes overloading of functions?

    • A.

      Virtual polymorphism

    • B.

      Transient polymorphism

    • C.

      Ad-hoc polymorphism

    • D.

      Pseudo polymorphism

    Correct Answer
    C. Ad-hoc polymorpHism
    Explanation
    Ad-hoc polymorphism is the correct term to describe the overloading of functions. This refers to the ability of a function to perform different operations based on the type or number of arguments passed to it. It allows multiple functions with the same name but different parameter lists to coexist and be called based on the specific arguments provided. This allows for flexibility and code reusability by providing different implementations of a function for different data types or argument combinations.

    Rate this question:

  • 14. 

    Which of the following approach is adapted by C++?

    • A.

      Top-down

    • B.

      Left-right

    • C.

      Bottom-up

    • D.

      Right-left

    Correct Answer
    C. Bottom-up
    Explanation
    C++ follows the bottom-up approach. This means that the program starts executing from the lowest level of the hierarchy and gradually moves up to the higher levels. In C++, functions are defined before they are used, allowing the program to be organized in a way that functions can call each other in a hierarchical manner. This approach helps in efficient memory management and allows for better code organization and reusability.

    Rate this question:

  • 15. 

    Which of the following keyword is used to overload an operator?

    • A.

      Operator

    • B.

      Overload

    • C.

      Friend

    • D.

      Override

    Correct Answer
    A. Operator
    Explanation
    The keyword "operator" is used to overload an operator in C++. Overloading an operator allows us to redefine the behavior of an operator for user-defined types. This means we can use operators like +, -, *, /, etc. with our own custom classes or data types. By overloading an operator, we can define what it means to add, subtract, multiply, or divide objects of our own class.

    Rate this question:

  • 16. 

    Which inheritance type is used in the class given below? class A : public X, public Y {}

    • A.

      Multilevel inheritance

    • B.

      Multiple inheritance

    • C.

      Hybrid inheritance

    • D.

      Hierarchical Inheritance

    Correct Answer
    B. Multiple inheritance
    Explanation
    The class A is inheriting from two different classes, X and Y, using the public access specifier. This means that class A will have access to both the public and protected members of classes X and Y. This is an example of multiple inheritance, where a class can inherit from multiple base classes.

    Rate this question:

  • 17. 

    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 templates, where different functions or templates can be called based on the types of arguments passed. Runtime polymorphism is achieved through inheritance and virtual functions, where a base class pointer can point to objects of different derived classes, and the appropriate function is called based on the actual object type at runtime.

    Rate this question:

  • 18. 

    Destructor has the same name as the constructor and it is preceded by ______ .

    • A.

      !

    • B.

      ?

    • C.

      ~

    • D.

      $

    Correct Answer
    C. ~
    Explanation
    The destructor has the same name as the constructor and is preceded by the tilde (~) symbol. This symbol is used to indicate that the function is a destructor.

    Rate this question:

  • 19. 

    If the copy constructor receives its arguments by value, the copy constructor would

    • A.

      Call one-argument constructor of the class

    • B.

      Work without any problem

    • C.

      Call itself recursively

    • D.

      Call zero-argument constructor

    Correct Answer
    C. Call itself recursively
    Explanation
    If the copy constructor receives its arguments by value, it means that the copy constructor is being called with a copy of an object as its argument. In this case, if the copy constructor calls itself recursively, it would create an infinite loop where the copy constructor keeps calling itself with copies of the object. This would lead to a stack overflow error and the program would crash. Therefore, the correct answer is that the copy constructor would call itself recursively.

    Rate this question:

  • 20. 

    Which of the following implicitly creates a default constructor when the programmer does not explicitly define at least one constructor for a class?

    • A.

      Linker

    • B.

      Preprocessor

    • C.

      Compiler

    • D.

      Loader

    Correct Answer
    C. Compiler
    Explanation
    The compiler implicitly creates a default constructor when the programmer does not explicitly define at least one constructor for a class. A default constructor is a constructor with no parameters, and it is automatically generated by the compiler if no other constructors are defined. This default constructor initializes the member variables of the class with their default values.

    Rate this question:

  • 21. 

    Which of the following never requires any arguments?

    • A.

      Member function

    • B.

      Friend function

    • C.

      Const function

    • D.

      Default constructor

    Correct Answer
    D. Default constructor
    Explanation
    A default constructor is a special type of member function that is automatically called when an object of a class is created without any arguments. It is used to initialize the object's data members to their default values. Unlike other types of functions, a default constructor does not require any arguments to be passed to it. Therefore, it never requires any arguments.

    Rate this question:

  • 22. 

    To ensure that every object in the array receives a destructor call, always delete memory allocated as an array with operator __________ .

    • A.

      Delete[ ]

    • B.

      Delete

    • C.

      Kill[ ]

    • D.

      Free[ ]

    Correct Answer
    A. Delete[ ]
    Explanation
    To ensure that every object in the array receives a destructor call, it is necessary to use the "delete[]" operator. This operator is specifically designed to deallocate memory that was allocated using the "new[]" operator for arrays. Using the "delete" operator without the square brackets would only deallocate memory for a single object, not an array of objects. Similarly, "kill[]" and "free[]" are not valid operators in C++ for deallocating memory. Therefore, the correct operator to use in this case is "delete[]".

    Rate this question:

  • 23. 

    Which of the following function prototype is perfectly acceptable?

    • A.

      Int Function(int Tmp = Show());

    • B.

      Float Function(int Tmp = Show(int, float));

    • C.

      Float = Show(int, float) Function(Tmp);

    • D.

      None of these

    Correct Answer
    A. Int Function(int Tmp = Show());
    Explanation
    The correct answer is "int Function(int Tmp = Show());" because it is a valid function prototype. It declares a function named "Function" that takes an integer parameter "Tmp" with a default value set to the result of the function "Show()". This means that if no argument is provided when calling the "Function" function, it will use the default value returned by "Show()".

    Rate this question:

  • 24. 

    Which of the following statement will be correct if the function has three arguments passed to it?

    • A.

      The trailing argument will be the default argument.

    • B.

      The first argument will be the default argument.

    • C.

      The middle argument will be the default argument.

    • D.

      All the argument will be the default argument.

    Correct Answer
    A. The trailing argument will be the default argument.
    Explanation
    If a function has three arguments passed to it, the trailing argument will be the default argument. This means that the first two arguments will be explicitly passed by the caller, while the third argument will take on its default value as defined in the function's declaration.

    Rate this question:

  • 25. 

    Which of the following statement is correct?

    • A.

      Only one parameter of a function can be a default parameter.

    • B.

      Minimum one parameter of a function must be a default parameter.

    • C.

      All the parameters of a function can be default parameters.

    • D.

      No parameter of a function can be default.

    Correct Answer
    C. All the parameters of a function can be default parameters.
    Explanation
    In Python, all the parameters of a function can be default parameters. Default parameters allow us to assign a default value to a parameter, which is used when the argument for that parameter is not provided. This means that if no arguments are passed for any of the parameters, the default values will be used. Having all parameters as default parameters gives us flexibility in calling the function with any combination of arguments, as any missing arguments will use their default values.

    Rate this question:

  • 26. 

    Where the default value of parameter have to be specified?

    • A.

      Function prototype

    • B.

      Function definition

    • C.

      Function call

    • D.

      None of these

    Correct Answer
    A. Function prototype
    Explanation
    The default value of a parameter has to be specified in the function prototype. The function prototype is a declaration of the function that includes the function name, return type, and parameter types. It allows the compiler to know about the function before it is defined or called. By specifying the default value in the function prototype, the compiler knows what value to use for the parameter if no argument is provided during the function call.

    Rate this question:

  • 27. 

    Which of the following function / types of function cannot have default parameters?

    • A.

      Member function of class

    • B.

      Main()

    • C.

      Member function of structure

    • D.

      All of these

    Correct Answer
    B. Main()
    Explanation
    Main() function cannot have default parameters because it is the entry point of a program and it must follow a specific signature defined by the programming language. The main() function is called by the operating system to start the execution of a program, and it expects a specific set of arguments (argc and argv) to be passed to it. Therefore, it cannot have default parameters as it would conflict with the expected signature.

    Rate this question:

  • 28. 

    Functions can be declared to return a reference type. There are reasons to make such a declaration/Which of the following reasons are correct?
    1. The information being returned is a large enough object that returning a reference is more efficient than returning a copy.
    2. The type of the function must be a R-value.

    • A.

      Only 1 is correct.

    • B.

      Only 2 is correct.

    • C.

      Both 1 and 2 are correct.

    • D.

      Both 1 and 2 are incorrect.

    Correct Answer
    C. Both 1 and 2 are correct.
    Explanation
    Both 1 and 2 are correct. Functions can be declared to return a reference type when the information being returned is a large enough object that returning a reference is more efficient than returning a copy. Additionally, the type of the function can be an R-value.

    Rate this question:

  • 29. 

    A reference is declared using the _____ symbol.

    • A.

      &&

    • B.

      &

    • C.

      ||

    • D.

      !

    Correct Answer
    B. &
    Explanation
    The correct answer is "&". In programming, the "&" symbol is used to declare a reference variable. A reference variable is a type of variable that refers to an existing object in memory rather than holding its own value. By using the "&" symbol, a reference variable can be declared and assigned to an existing object, allowing multiple variables to refer to the same object.

    Rate this question:

  • 30. 

    Reference is like a _____. 

    • A.

      Structure

    • B.

      Pointer

    • C.

      Macro

    • D.

      Enum

    Correct Answer
    B. Pointer
    Explanation
    A pointer is a reference to a memory address that allows us to directly access and manipulate the data stored at that address. Similarly, a reference in programming is a type that refers to another type, allowing us to access and manipulate the data of the referenced type. Therefore, a pointer can be considered as a reference, making it the most suitable option for completing the analogy in the question.

    Rate this question:

  • 31. 

    Which stream class is to only write on files ?

    • A.

      Ofstream

    • B.

      Ifstream

    • C.

      Fstream

    • D.

      Iostream

    Correct Answer
    A. Ofstream
    Explanation
    ofstream is the correct answer because it is a stream class in C++ that is used specifically for writing data to files. It is derived from the ostream class and provides functions and operators to write data to output files. ifstream, on the other hand, is used for reading data from input files, fstream is used for both reading and writing, and iostream is a base class for both input and output streams but does not specifically cater to file operations.

    Rate this question:

  • 32. 

    Which among following is used to open a file in binary mode ?

    • A.

      Ios:app

    • B.

      Ios::out

    • C.

      Ios::in

    • D.

      Ios::binary

    Correct Answer
    D. Ios::binary
    Explanation
    The correct answer is ios::binary. This is because ios::binary is used to open a file in binary mode. Binary mode is used when dealing with non-text files, such as image or audio files, where the data is represented in binary format instead of characters.

    Rate this question:

  • 33. 

    Which is correct syntax ?

    • A.

      Myfile:open ("example.bin", ios::out);

    • B.

      Myfile.open ("example.bin", ios::out);

    • C.

      Myfile::open ("example.bin", ios::out);

    • D.

      Myfile.open ("example.bin", ios:out);

    Correct Answer
    B. Myfile.open ("example.bin", ios::out);
    Explanation
    The correct syntax is myfile.open ("example.bin", ios::out); because it uses the correct syntax for opening a file with the specified filename and mode. The ios::out flag is used to open the file in output mode, allowing writing to the file.

    Rate this question:

  • 34. 

    How to get position to the nth byte of fileObject ?

    • A.

      FileObject.seekg( 'filename',n );

    • B.

      FileObject.seekg( n );

    • C.

      FileObject.seekg( n, 'filename' );

    • D.

      FileObject.seekg( n, ios::app );

    Correct Answer
    B. FileObject.seekg( n );
    Explanation
    The correct answer is fileObject.seekg( n ). This is because the seekg() function is used to set the position of the next character to be extracted from the input stream associated with the fileObject. It takes the offset value n as its argument and sets the position to the nth byte in the file. The other options provided in the question are incorrect syntax or use incorrect arguments for the seekg() function.

    Rate this question:

  • 35. 

     What is meant by multiple inheritance?

    • A.

      Deriving a base class from derived class

    • B.

      Deriving a derived class from base class

    • C.

      Deriving a derived class from more than one base class

    • D.

      None of the mentioned

    Correct Answer
    C. Deriving a derived class from more than one base class
    Explanation
    Multiple inheritance refers to the concept of deriving a derived class from more than one base class. In this scenario, the derived class inherits the properties and behaviors of multiple base classes, allowing it to access and use the features of each base class. This allows for greater flexibility in designing and implementing class hierarchies, as it enables the derived class to combine the characteristics of multiple base classes.

    Rate this question:

  • 36. 

    Which symbol is used to create multiple inheritance? 

    • A.

      Dot

    • B.

      Comma

    • C.

      Dollar

    • D.

      None of the mentioned

    Correct Answer
    B. Comma
    Explanation
    Comma is used to create multiple inheritance in some programming languages, such as C++. Multiple inheritance allows a class to inherit from more than one base class, and the comma is used to separate the names of the base classes in the class declaration. This allows the derived class to inherit the properties and behaviors from multiple parent classes.

    Rate this question:

  • 37. 

    Which of the following advantages we lose by using multiple inheritance? 

    • A.

      Dynamic binding

    • B.

      Polymorphism

    • C.

      Both of the above

    • D.

      None of these

    Correct Answer
    C. Both of the above
    Explanation
    When using multiple inheritance, we lose the advantage of dynamic binding and polymorphism. Dynamic binding allows the selection of the appropriate function at runtime based on the object type, while polymorphism allows objects of different classes to be treated as objects of a common superclass. However, with multiple inheritance, conflicts may arise when two base classes have the same function name, leading to ambiguity and making it difficult to determine which function should be called. This results in the loss of dynamic binding and polymorphism advantages.

    Rate this question:

  • 38. 

     Which design patterns benefit from the multiple inheritance? 

    • A.

      Adapter and observer pattern

    • B.

      Code pattern

    • C.

      Glue pattern

    • D.

      None of the mentioned

    Correct Answer
    A. Adapter and observer pattern
    Explanation
    The adapter and observer patterns benefit from multiple inheritance because they involve the need to inherit from multiple classes or interfaces. The adapter pattern allows objects with incompatible interfaces to work together by adapting one interface to another, and multiple inheritance can be used to inherit from both the target interface and the adapting class. The observer pattern involves a one-to-many relationship between objects, where multiple inheritance can be used to inherit from both the subject being observed and the observer interface. Therefore, these patterns can benefit from multiple inheritance.

    Rate this question:

  • 39. 

    Which is used to describe the function using placeholder types? 

    • A.

      Template parameters

    • B.

      template type parameters

    • C.

      Template type

    • D.

      None of the mentioned

    Correct Answer
    B. template type parameters
    Explanation
    Template type parameters are used to describe the function using placeholder types. These parameters allow the function to be flexible and work with different types of data without having to rewrite the function for each specific type. By using template type parameters, the function can be written once and then used with different types as needed.

    Rate this question:

  • 40. 

    Pick out the correct statement. 

    • A.

      you only need to write one function, and it will work with many different types.

    • B.

      it will take a long time to execute

    • C.

      Duplicate code is increased

    • D.

      None of these

    Correct Answer
    A. you only need to write one function, and it will work with many different types.
    Explanation
    This statement is correct because it suggests that by writing one function, it can be used with multiple types of data. This promotes code reusability and reduces the need for duplicating code for different data types.

    Rate this question:

  • 41. 

    What is data hiding ?

    • A.

      It is related with hiding internal object details

    • B.

      It is related with showing internal object details

    • C.

      It is related with datatypes

    • D.

      None of above

    Correct Answer
    A. It is related with hiding internal object details
    Explanation
    Data hiding is a concept in object-oriented programming that involves encapsulating the internal details of an object and preventing direct access to them from outside the object. This is done to ensure that the internal state and implementation of an object are not exposed to the external world, promoting security, modularity, and flexibility in software development. By hiding the internal details, the object can control how it is accessed and manipulated, providing a level of abstraction and protecting its integrity.

    Rate this question:

  • 42. 

    What is class in c++ ?

    • A.

      When you define a class, you define a blueprint for a data type.

    • B.

      When you define a class, you make get more funtionality.

    • C.

      When you define a class, you define the logic.

    • D.

      When you define a class, you make debugging.

    Correct Answer
    A. When you define a class, you define a blueprint for a data type.
    Explanation
    A class in C++ is a blueprint for creating objects of a particular data type. It defines the structure and behavior of the objects that will be created based on the class. By defining a class, you specify the attributes (data members) and methods (member functions) that the objects of that class will have. This allows you to create multiple objects of the same class, each with its own set of attributes and behavior. The class acts as a template or blueprint that can be used to create objects with similar characteristics.

    Rate this question:

  • 43. 

     What is object in C++ ?

    • A.

      Object is part of syntax of a class.

    • B.

      Object is datatype of a class.

    • C.

      Object is an instance of a class.

    • D.

      Object is function of a class.

    Correct Answer
    C. Object is an instance of a class.
    Explanation
    In C++, an object is an instance of a class. A class is a blueprint or template that defines the properties and behaviors of objects. When we create an object, we are essentially creating a specific instance of that class, with its own unique set of values for the member variables. This allows us to create multiple objects of the same class, each with its own distinct characteristics and behaviors.

    Rate this question:

  • 44. 

    What is purpose of abstract class ?

    • A.

      To provide help with database connectivity.

    • B.

      To provide data input to other classes.

    • C.

      To provide security to other classes.

    • D.

      To provide an appropriate base class from which other classes can inherit.

    Correct Answer
    D. To provide an appropriate base class from which other classes can inherit.
    Explanation
    An abstract class is designed to serve as a blueprint or template for other classes to inherit from. It cannot be instantiated on its own but provides a common structure and behavior that can be shared by its subclasses. This allows for code reusability and promotes a hierarchical organization of classes. It also enforces the implementation of certain methods or properties in its subclasses, ensuring that they adhere to a specific contract. Therefore, the purpose of an abstract class is to provide an appropriate base class from which other classes can inherit.

    Rate this question:

  • 45. 

    What is default visibility mode for members of classes in C++ ?

    • A.

      Private

    • B.

      Public

    • C.

      Protected

    • D.

      Depends

    Correct Answer
    A. Private
    Explanation
    In C++, the default visibility mode for members of classes is private. This means that by default, the members of a class are only accessible within the class itself and cannot be accessed from outside the class. Private members can only be accessed through public member functions or friend functions.

    Rate this question:

  • 46. 

    Which one do you like?

    • A.

      Option 1

    • B.

      Option 2

    • C.

      Option 3

    • D.

      Option 4

    Correct Answer
    A. Option 1
  • 47. 

    Which among following is not a valid visibility mode in c++ program ?

    • A.

      Private

    • B.

      Public

    • C.

      Protected

    • D.

      Limited

    Correct Answer
    D. Limited
    Explanation
    The visibility modes in C++ determine the accessibility of class members. Private members can only be accessed within the class, public members can be accessed from anywhere, and protected members can be accessed within the class and its derived classes. However, "Limited" is not a valid visibility mode in C++.

    Rate this question:

  • 48. 

    Which one do you like?

    • A.

      Option 1

    • B.

      Option 2

    • C.

      Option 3

    • D.

      Option 4

    Correct Answer
    A. Option 1
    Explanation
    The given question asks for personal preference, so the correct answer would depend on the individual's liking. Since the answer provided is "Option 1," it implies that the person prefers the first option among the given choices.

    Rate this question:

  • 49. 

     How we can define member function outside the class ?

    • A.

      Using union

    • B.

      Using structure

    • C.

      Using pointers

    • D.

      Using scope resolution

    Correct Answer
    D. Using scope resolution
    Explanation
    Member functions in C++ can be defined outside the class by using the scope resolution operator (::). This allows the member function to be defined separately from the class declaration, providing better organization and readability of the code. By using the scope resolution operator, the function can be associated with the class and accessed using the class name followed by the scope resolution operator. This method is commonly used when the function implementation is lengthy or when the class has multiple member functions.

    Rate this question:

  • 50. 

    Which among following is correct way of declaring object of a class ?

    • A.

      Classname Objectname;

    • B.

      Class Classname Objectname;

    • C.

      Class Classname Object Objectname;

    • D.

      Classname Object Objectname;

    Correct Answer
    A. Classname Objectname;
    Explanation
    The correct way of declaring an object of a class is by using the syntax "Classname Objectname;". This syntax creates an instance of the class with the specified name. The other options provided in the question are incorrect syntax for declaring objects in C++.

    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
  • Mar 19, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Aug 14, 2015
    Quiz Created by
    Rabib
Back to Top Back to top
Advertisement