0% found this document useful (0 votes)
12 views8 pages

OOPSvivaquestion(SnapED)

Uploaded by

princeku20401
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views8 pages

OOPSvivaquestion(SnapED)

Uploaded by

princeku20401
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Viva Voce

Questions
Subject Object Orientd Programming Using Code CIC-211
C++

Community SnapED Community

Question: What is Object-Oriented Programming (OOP)?

Answer: Object-Oriented Programming (OOP) is a programming paradigm that revolves around the
concept of "objects," which can contain data and code to manipulate that data.

Question: Define a class in C++.

Answer: A class in C++ is a user-defined data type that defines the properties (data members) and
behaviors (member functions) of objects.

Question: What is an object in C++?

Answer: An object in C++ is an instance of a class. It is a variable of the class type and can hold data
and call member functions defined in the class.

Question: Explain the four fundamental principles of OOP.

Answer: The four fundamental principles of OOP are encapsulation, inheritance, polymorphism, and
abstraction.

Question: What is encapsulation in OOP?

Answer: Encapsulation is the bundling of data (attributes) and methods (functions) that operate on
the data within a class, protecting the data from unauthorized access.

Question: How is data abstraction achieved in C++?

Created by Snaped Team


Answer: Data abstraction is achieved by providing a public interface while hiding the implementation
details. This allows the user to use the class's functionalities without knowing how they are
implemented.

Question: What is inheritance in C++?

Answer: Inheritance is the mechanism by which a class can inherit the properties (data members and
member functions) of another class. It promotes code reuse and establishes a relationship between
classes.

Question: Explain the types of inheritance in C++.

Answer: In C++, inheritance can be of four types: single inheritance, multiple inheritance, hierarchical
inheritance, and multilevel inheritance.

Question: What is polymorphism in C++?

Answer: Polymorphism allows objects to be treated as instances of their parent class, enabling
different implementations for methods in derived classes.

Question: How is polymorphism achieved in C++?

Answer: Polymorphism is achieved through function overloading and function overriding. Function
overloading involves defining multiple functions with the same name but different parameters, while
function overriding involves redefining a function in a derived class.

Question: What is function overloading in C++?

Answer: Function overloading is when multiple functions have the same name but different
parameters (different types or a different number of parameters).

Question: How does function overloading relate to polymorphism?

Answer: Function overloading is a form of compile-time polymorphism, as the appropriate function to


be called is determined at compile time based on the function's signature.

Created by Snaped Team


Question: Explain function overriding in C++.

Answer: Function overriding is when a function in a derived class has the same signature (name and
parameters) as a function in its base class. The function in the derived class replaces the function in
the base class during runtime polymorphism.

Question: Describe the 'virtual' keyword in C++.

Answer: The 'virtual' keyword is used to declare a function as virtual in a base class. Virtual functions
can be overridden in derived classes, enabling runtime polymorphism.

Question: How are pure virtual functions used in C++?

Answer: A pure virtual function is a virtual function that has no implementation in the base class and
is marked with '= 0'. It acts as a placeholder for the derived classes to implement.

Question: What is an abstract class in C++?

Answer: An abstract class is a class that contains one or more pure virtual functions. Instances of an
abstract class cannot be created, and it is meant to be subclassed.

Question: Explain the concept of constructors in C++.

Answer: Constructors are special member functions of a class that are automatically called when an
object is created. They initialize the object's state and allocate resources if needed.

Question: What is a destructor in C++?

Answer: A destructor is a special member function of a class that is called when an object is destroyed
or goes out of scope. It is used to release resources held by the object.

Question: Differentiate between a constructor and a destructor.

Created by Snaped Team


Answer: Constructors are called when an object is created, while destructors are called when an
object is destroyed or goes out of scope. Constructors initialize the object, and destructors release
resources held by the object.

Question: What is the difference between default and parameterized constructors?

Answer: A default constructor is one that can be called without any arguments, while a parameterized
constructor accepts parameters that are used to initialize the object's state.

Question: Explain the concept of a copy constructor.

Answer: A copy constructor is a constructor that initializes an object using another object of the same
class. It creates a new object with the same values as the existing object.

Question: What is operator overloading in C++?

Answer: Operator overloading allows operators (such as +, -, *, /) to be used with user-defined data
types (classes). It enables custom operations for these operators with class objects.

Question: Explain the 'this' pointer in C++.

Answer: The 'this' pointer is a pointer that holds the memory address of the current object. It is used
to refer to the current instance of the class within its member functions.

Question: What are static members in a class in C++?

Answer: Static members (data members or functions) in a class are shared among all instances of the
class. They belong to the class itself, not to individual objects.

Question: Describe the 'friend' function in C++.

Answer: A 'friend' function is a function that is not a member of a class but is granted access to the
class's private and protected members. It is declared using the 'friend' keyword.

Question: What is a friend class in C++?

Created by Snaped Team


Answer: A friend class is a class that is granted access to the private and protected members of
another class. It is declared using the 'friend' keyword.

Question: What is the purpose of the 'const' keyword in C++?

Answer: The 'const' keyword in C++ is used to declare variables or functions as constant, indicating
that they cannot be modified.

Question: Explain dynamic memory allocation in C++.

Answer: Dynamic memory allocation in C++ is the process of allocating memory at runtime using
operators like 'new' and deallocating it using 'delete'. It is used for creating objects with a lifetime
determined during runtime.

Question: What is a destructor? Why is it important?

Answer: A destructor is a special member function of a class that is automatically called when an
object is destroyed. Its purpose is to release resources held by the object, ensuring proper cleanup
and preventing memory leaks.

Question: How do you prevent an object from being copied in C++?

Answer: To prevent object copying, you can make the copy constructor and the assignment operator
private or delete them in the class definition, or you can inherit privately from a non-copyable base
class.

Question: Explain function templates in C++.

Answer: Function templates in C++ allow you to write a single function that can work with different
data types. The data type is determined by the type of arguments passed during function invocation.

Question: What are member initializer lists in C++?

Answer: Member initializer lists are used in constructors to initialize class members before the
constructor body executes. They follow a colon and a comma-separated list of member initializations.

Created by Snaped Team


Question: What is operator precedence in C++?

Answer: Operator precedence determines the order in which operators are evaluated in an
expression. It is crucial to understand this order to avoid unexpected behavior in expressions.

Question: Explain the 'typeid' operator in C++.

Answer: The 'typeid' operator in C++ allows you to obtain type information about an expression or a
type. It is often used for runtime type identification.

Question: What is the 'const_cast' operator in C++?

Answer: The 'const_cast' operator is used to add or remove the 'const' qualifier from a variable. It
allows you to modify a 'const' object.

Question: Explain the 'dynamic_cast' operator in C++.

Answer: The 'dynamic_cast' operator is used for safe downcasting of pointers or references to classes
in an inheritance hierarchy. It performs a runtime check to ensure the conversion is valid.

Question: Describe the 'reinterpret_cast' operator in C++.

Answer: The 'reinterpret_cast' operator is used for type casting that allows casting between unrelated
types, like converting a pointer to an integer type. It's a low-level cast and should be used with
caution.

Question: What is the difference between 'static_cast' and 'dynamic_cast'?

Answer: 'static_cast' is used for safe and explicit type conversions at compile time, while
'dynamic_cast' is used for safe type conversions during runtime and is primarily used for polymorphic
base-to-derived conversions.

Question: What is a namespace in C++?

Created by Snaped Team


Answer: A namespace in C++ is a way to organize code elements, such as classes, functions, and
variables, into a named scope to prevent naming conflicts and make the code more modular and
maintainable.

Question: What is function hiding in C++?

Answer: Function hiding occurs when a derived class defines a function with the same name as a
function in its base class, making the base class function inaccessible in the derived class.

Question: How can you achieve method overriding in C++?

Answer: Method overriding in C++ involves redefining a virtual function in a derived class with the
same signature as the virtual function in the base class. This enables the derived class to provide its
implementation.

Question: What are access specifiers in C++ classes?

Answer: Access specifiers (public, private, protected) in C++ classes determine the visibility and
accessibility of class members. Public members are accessible from outside the class, private members
are accessible only within the class, and protected members are accessible within the class and
derived classes.

Question: Explain the purpose of 'const' member functions in C++.

Answer: 'const' member functions are member functions that do not modify the object's state. They
are used to read data members and ensure the object's integrity is maintained.

Question: What is a friend function? When is it used?

Answer: A friend function is a function that is not a member of a class but has access to its private and
protected members. It is used when a function needs to access class internals without being a
member of the class.

Question: What is the role of a copy assignment operator in C++?

Created by Snaped Team


Answer: The copy assignment operator (operator=) is used to define how an object of a class should
be assigned the value of another object of the same class. It is crucial for proper assignment behavior.

Question: Explain the 'inline' function in C++.

Answer: The 'inline' function is a function declared with the 'inline' keyword, suggesting the compiler
to insert the function's code at the point of its call, saving the overhead of function invocation.

Question: What is a const reference in C++?

Answer: A const reference is a reference that is bound to a variable and cannot be used to modify the
variable's value. It is often used to pass variables to functions without allowing modification.

Question: How does C++ support multiple inheritances?

Answer: C++ supports multiple inheritances by allowing a class to inherit from multiple base classes.
This means a class can have multiple parent classes.

Question: What are virtual destructors in C++?

Answer: A virtual destructor is a destructor declared as virtual in a base class. It ensures that the
destructor of the most derived class is called when deleting a pointer to a base class type.

Question: Explain early binding and late binding in C++.

Answer: Early binding, also known as static binding, occurs during compile time and involves resolving
the method calls based on the declared type. Late binding, also known as dynamic binding, occurs at
runtime and involves resolving method calls based on the actual type of the object.

Created by Snaped Team

You might also like