0% found this document useful (0 votes)
30 views7 pages

GFGHNV

The document discusses various object-oriented programming concepts like class, object, inheritance, polymorphism, encapsulation, and abstraction. It also covers break statements, derived and base classes.

Uploaded by

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

GFGHNV

The document discusses various object-oriented programming concepts like class, object, inheritance, polymorphism, encapsulation, and abstraction. It also covers break statements, derived and base classes.

Uploaded by

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

1. *What is an object?

An object is an instance of a class in object-oriented programming. It encapsulates data and


behavior related to that data within a single unit. Objects are created based on the blueprints
provided by their respective classes, which define the structure (attributes) and capabilities
(methods) of the objects.

2. *What are the uses of the “this” pointer?*

- To differentiate between member variables and parameters or local variables with the same
name.

- To return the reference to the current object.

- To pass the current object as an argument to another function.

4. *What is the use of the “new” operator?*

The new operator in C++ is used to allocate memory dynamically for objects or variables at
runtime. It returns a pointer to the allocated memory.

5. *What do you mean by data binding?*

Data binding refers to the process of linking data with the corresponding code that manipulates it.
It includes the techniques of connecting data sources to user interface elements, allowing for
automatic updates when the data changes. In object-oriented programming, data binding often
refers to the association of method calls with the data in objects.

6. *Define: “Inheritance”*

Inheritance is a fundamental concept in object-oriented programming where a new class (derived


class) is created from an existing class (base class). The derived class inherits attributes and
behaviors (methods) from the base class and can also have additional attributes and methods or
override existing ones.

8. *Write a note on exception.*

An exception is a runtime error or unexpected event that occurs during the execution of a
program, disrupting its normal flow. Exceptions are handled using try-catch blocks in C++ to ensure
the program can manage errors gracefully without crashing..

9. *What is an abstract class?*

An abstract class in C++ is a class that cannot be instantiated on its own and is designed to be a
base class for other classes. It contains at least one pure virtual function, which must be overridden
by derived classes.
10. *What are string attributes?*

In the context of programming, string attributes refer to properties or methods associated with
string objects or variables. Attributes might include the length of the string, methods to concatenate,
compare, or manipulate strings, and metadata about the string.

12. *What is a file mode?*

A file mode in C++ specifies the operations allowed on a file when it is opened.

- ios::in: Open for reading.

- ios::out: Open for writing.

- ios::app: Open for appending.

- ios::binary: Open in binary mode.

1. I/O Stream*:

- *Definition*: I/O stands for Input/Output. In programming, an I/O stream is an abstraction that
represents the flow of data to and from input/output devices. Common examples include reading
from a keyboard (input) or writing to a console or file (output)

2. **Member Function**:

- **Definition**: A member function is a function that is defined as part of a class. It operates on


the objects of the class and has access to the class's data members.

3. **Keyword**:

- **Definition**: Keywords are reserved words in a programming language that have a special
meaning and cannot be used as identifiers (names for variables, functions, etc.). They define the
syntax and structure of the programming language.

- **Examples**: `int`, `return`, `class`, `if`, `else`.

5. *Distinguish between Class and Object*:

- *Class*: A blueprint or template for creating objects. It defines properties (data members) and
behaviors (member functions).

- *Object*: An instance of a class. It is a concrete entity that has state and behavior as defined by
its class.

6. *Types of Constructors*:

- *Default Constructor*: A constructor that takes no arguments.

- *Parameterized Constructor*: A constructor that takes one or more arguments.

- *Copy Constructor*: A constructor that initializes an object using another object of the same class
7. *Inheritance*:

- *Definition*: Inheritance is an OOP concept where a new class (derived class) is created from an
existing class (base class). The derived class inherits attributes and methods of the base class,
allowing for code reuse and polymorphism.

8. *Data Abstraction*:

- *Definition*: Data abstraction is the process of hiding the internal details and showing only the
essential features of an object. It helps in reducing complexity and allows focusing on the
interactions with the object.

9. *File*:

- *Definition*: A file is a named location on storage media that stores data permanently. It can be a
text file, binary file, etc.

- *Example*: Files are used for storing information persistently, such as document files, image files,
or executable files

10. *How to Open and Close Files*:

- *Opening a File*: Use the open method in languages like C++ or Python.

- *Closing a File*: Use the close method to close the file and release.

11. *Function Prototype*:

- *Definition*: A function prototype is a declaration of a function that specifies its name, return
type, and parameters without the function body. It informs the compiler about the function's
existence before its actual definition.

12. *Virtual Functions*:

- *Definition*: Virtual functions allow derived classes to override functions in base classes. They
are declared using the virtual keyword in the base class.

1. What is a class?*

- A class in programming, particularly in object-oriented programming (OOP), is a blueprint for


creating objects. It defines a set of properties (attributes) and methods (functions) that the created
objects can have. Classes encapsulate data and functions that operate on the data into a single unit.

2. *Differentiate between data hiding and encapsulation.*

- *Data Hiding:* This refers to the practice of restricting access to certain details of an object or a
class. It is achieved using access specifiers like private, protected, and public in C++. The primary goal
is to protect object integrity by preventing unauthorized or accidental modification.

- *Encapsulation:* This is the process of bundling data (variables) and methods (functions) that
operate on the data into a single unit, typically a class. Encapsulation helps to hide the internal state
and only expose necessary functionalities, thus providing a clear interface and enhancing
maintainability and flexibility.
3. *What do you mean by function overloading?*

- Function overloading in C++ is the ability to create multiple functions with the same name but
different parameters (either in number or type). The compiler differentiates these functions based
on the signature, which includes the number and type of parameters.

4. *List the operators that cannot be overloaded.*

- The operators that cannot be overloaded in C++ are:

- :: (Scope resolution operator)

- . (Member access or dot operator)

- .* (Member pointer access operator)

- ?: (Ternary or conditional operator)

- sizeof (Size-of operator)

- typeid (Type identification operator)

5. *What are derived and base classes?*

- *Base Class:* Also known as a parent or superclass, a base class is the class being inherited from.
It provides properties and methods that can be reused by derived classes.

- *Derived Class:* Also known as a child or subclass, a derived class is a class that inherits
properties and methods from another class (the base class). It can add new properties and methods
or override existing ones from the base class.

6. *Write down the use of data binding.*

- Data binding is the process of connecting a data source (such as a database or a variable) to a
user interface element (such as a text box or a label). It simplifies the process of keeping the user
interface synchronized with the underlying data, making it easier to create dynamic and responsive
applications.

8. *What is “this” pointer?*

- The this pointer in C++ is an implicit pointer available inside a class's non-static member
functions. It points to the object for which the member function is called. It is used to access
members and differentiate between member variables and parameters with the same name.

11. *What are string attributes?*

- String attributes refer to the properties and methods available for string objects in C++. For
example, in the std::string class, attributes include the length of the string, capacity, and various
member functions like substr(), find(), append(), etc.

12. *Define: “File”.*

- In computing, a file is a resource for storing information, which is available to a computer


program and is usually based on some kind of durable storage (like a hard drive). Files are used to
store data permanently and can be opened, read, written, and closed by programs using file
handling functions. In C++, file handling is done using classes like ifstream, ofstream, and fstream
from the <fstream> library.
1. *Basic Concepts of Object-Oriented Programming (OOP)*:

- *Class*: A blueprint for creating objects. It defines a datatype by bundling data and methods that
operate on the data.

- *Object*: An instance of a class. Objects have state and behavior.

- *Inheritance*: The mechanism by which one class (derived class) inherits the properties and
behavior of another class (base class).

- *Polymorphism*: The ability of different classes to be treated as instances of the same class
through inheritance. It allows methods to do different things based on the object it is acting upon.

- *Encapsulation*: The bundling of data and methods that operate on that data within one unit
(class) and restricting access to some of the object's components.

- *Abstraction*: The concept of hiding the complex implementation details and showing only the
necessary features of an object.

2. *General Form of Break Statement*:

cpp

break;

3. *Derived and Base Classes*:

- *Base Class*: The class whose properties and methods are inherited by another class.

- *Derived Class*: The class that inherits the properties and methods of the base class.

4. *Operators That Cannot Be Overloaded*:

- Scope resolution operator (::)

- Member selection operator (.)

- Member selection through pointer to function (.*)

- Conditional operator (?:)

5. *Difference Between Data Hiding and Encapsulation*:

- *Data Hiding*: Restricting access to the inner workings of a class and only allowing access
through public methods. It is achieved using access specifiers like private, protected, and public.

- *Encapsulation*: The process of bundling the data (variables) and the code (methods) that
operates on the data into a single unit, or class. Encapsulation enforces data hiding.

6. *Difference Between Constructor and Destructor*:

- *Constructor*: A special member function of a class that initializes objects. It is called when an
object is created.

- *Destructor*: A special member function of a class that cleans up when an object is destroyed. It
is called when an object goes out of scope or is explicitly deleted
7. *Dynamic Object*:

A dynamic object is an object that is created and managed at runtime using dynamic memory
allocation. In C++, dynamic objects are created using the new keyword and destroyed using the
delete keyword.

8. *Example for Type Conversion*:

cpp

int i = 10;

double d = static_cast<double>(i); // Type conversion from int to double

9. *Virtual Base Classes*:

Virtual base classes are used in multiple inheritance to avoid multiple instances of a base class
appearing in an inheritance hierarchy when the same base class is inherited indirectly through
multiple paths

10. *Virtual Functions*:

A virtual function is a function in a base class that can be overridden in a derived class. It is
declared using the virtual keyword. Virtual functions enable polymorphism, allowing for dynamic
method binding.

11. *File*:

A file is a named location on storage media that stores data permanently. It is used to store
information for long-term storage, which can be read or written to by a program.

12. *Use of Template*:

Templates in C++ allow functions and classes to operate with generic types. This means you can
create a function or class to work with any data type. Templates are useful for creating generic
libraries and avoiding code duplication.

1. *Distinguish between Procedure-oriented and Object-oriented programming:*

- *Procedure-oriented programming (POP):* Focuses on procedures or routines. Programs are


divided into small parts called functions, which perform specific tasks. It follows a top-down
approach. Examples include C and Fortran.

- *Object-oriented programming (OOP):* Focuses on objects that contain both data and methods
to manipulate the data. Programs are divided into objects. It follows a bottom-up approach and
supports concepts like encapsulation, inheritance, and polymorphism. Examples include Java, C++,
and Python.

2. *What is an object?*

- An object is an instance of a class in OOP. It contains data (attributes) and methods (functions)
that operate on the data. Objects represent real-world entities and interact with each other.

3. *Define the term: Identifiers.*

- Identifiers are names given to various programming elements such as variables, functions, arrays,
and classes. They are used to uniquely identify these elements within the program.
4. *What are Arrays?*

- Arrays are data structures that can hold multiple values of the same type. The elements in an
array are stored in contiguous memory locations and can be accessed using an index.

5. *Mention the use of Inheritance.*

- Inheritance allows a class (derived class) to inherit properties and behaviors (methods) from
another class (base class). This promotes code reusability and establishes a relationship between
classes.

6. *Define the term: Functions.*

- Functions are blocks of code that perform specific tasks and can be called by name. They may
take inputs (parameters), execute a series of statements, and return an output.

7. *What is Call by reference?*

- Call by reference is a method of passing arguments to a function where the address of the
argument is passed rather than its value. This allows the function to modify the actual parameter
used in the call.

8. *What is Reusability in classes?*

- Reusability in classes refers to the ability to use existing classes to create new classes or objects,
reducing the need to write redundant code. This can be achieved through inheritance, composition,
and aggregation.

9. *Differentiate Base class and Derived Class.*

- *Base class (Parent class or Superclass):* The class from which properties and behaviors are
inherited. It provides the basic attributes and methods.

- *Derived class (Child class or Subclass):* The class that inherits properties and behaviors from the
base class and can add new attributes and methods or override existing ones.

10. *Define: Polymorphism.*

- Polymorphism is a concept in OOP that allows methods to have different behaviors based on the
object that calls them. It can be achieved through method overloading (compile-time polymorphism)
and method overriding (runtime polymorphism).

11. *How to read and write files?*

- Reading and writing files typically involve using file handling functions provided by a
programming language. For example, in Python:

- *Reading:* Use open('filename', 'r') to open a file for reading and then use methods like read(),
readline(), or readlines().

- *Writing:* Use open('filename', 'w') or open('filename', 'a') to open a file for writing or
appending and then use write() or writelines().

You might also like