0% found this document useful (0 votes)
4 views4 pages

C++ Object-Oriented Programming Concepts

The document outlines key concepts of Object-Oriented Programming, specifically focusing on access specifiers, static members, constructors, destructors, operator overloading, and type conversion in C++. It includes definitions, characteristics, and rules related to these concepts, as well as examples and exercises for practical understanding. Additionally, it provides tasks for further exploration of these topics through programming assignments.

Uploaded by

venkatp4002442
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)
4 views4 pages

C++ Object-Oriented Programming Concepts

The document outlines key concepts of Object-Oriented Programming, specifically focusing on access specifiers, static members, constructors, destructors, operator overloading, and type conversion in C++. It includes definitions, characteristics, and rules related to these concepts, as well as examples and exercises for practical understanding. Additionally, it provides tasks for further exploration of these topics through programming assignments.

Uploaded by

venkatp4002442
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

VELAMMAL ENGINEERING COLLEGE

DEPARTMENT OF ELECTRONICS AND INSTRUMENTATION


23CS211T OBJECT ORIENTED PROGRAMMING

UNIT II - 2 Marks

[Link] out access specifier?


●​ Private
●​ Public
●​ Protected

[Link] are the characteristics of a static data member ?


· Static data member is initialized to zero when the first object of its class is
created. No other initialization is permitted.
· Only one copy of that member is created for the entire class and is shared by all
the objects of that class, no matter how many objects are created.
· It is visible only within the class, but its life time is the entire program.

[Link] are the properties of a static member function ?


· A static function can have access to only other static members, declared in the
same class.
· A static member function can be called using the class name as follows
Classname :: function-name;

[Link] is an inline function ?


Inline functions are those whose function body is inserted in place of the function
call statement during the compilation process. With the inline code the program
will not incur any context switching overhead.

[Link] are the properties of a friend function ?


· A friend function is not in the scope of the class to which it has been declared as
friend.
· It can be invoked like a normal function without the help of any object.
· Unlike member functions it cannot access the member names directly and has to
use an object name and dot membership with each member name.
It uses object as its argument.

[Link] is the difference between friend function and member function ?


The only difference between a friend function and member function is that, the
friend function requires the argument to be explicitly passed to the function and
processes them explicitly, whereas, the member function considers the first
argument implicitly.

[Link] is a constructor ?
A constructor is a special member function whose task is to initialize the objects of
its class.
It is special because its name is the same as the class name.
The constructor is invoked whenever an object of its associated class is created.

[Link] are the characteristics of a constructor ?


· They should be declared in the public section.
· They are invoked automatically when the objects are created.
· They do not have return types, not even void and therefore, they cannot return
values.
· They cannot be inherited, though a derived class can call the base class
constructor.
· Constructors cannot be virtual.

[Link] are the types of a constructor ?


· Default constructor
· Parameterized constructor.
· Copy constructor

[Link] is a destructor ?
A destructor as the name implies is used to destroy the objects that have been
created by a constructor. Like a constructor the destructor is a member function
whose name is the same as the class name but is preceded by a tilde symbol.
~ sample( )
{
}

[Link] is operator overloading?


C++ has the ability to provide the operators with a special meaning for a data type.
This mechanism of giving such special meanings to an operator is known as
Operator
overloading. It provides a flexible option for the creation of new definitions for
C++operators.
[Link] out the operators that cannot be overloaded using Friend function.
Assignment operator =
Function call operator ( )
Subscripting operator [ ]
Class member access operator (. , .*)

[Link] at least four rules for Operator overloading.


Only the existing operators can be overloaded.
The overloaded operator must have at least one operand that is of user defined data
type.
The basic meaning of the operator should not be changed.
Overloaded operators follow the syntax rules of the original operators. They cannot
be overridden.

[Link] out the operators that cannot be overloaded.


Class member access operator (. , .*)
Scope resolution operator (::)
Size operator ( sizeof )
Conditional operator (?:)

15. What are the Operators Used in Dynamic Object Creation


●​ new → Allocates memory and calls constructor
●​ delete → Deallocates memory and calls destructor
Example:
cpp
CopyEdit
ClassName* obj = new ClassName(); // dynamic creation
delete obj; // dynamic deletion

16. Is Explicit Typecasting Possible in C++? To Convert int x=60 to char c,write the

syntax for implicit type casting.


Yes, explicit typecasting is allowed using either C-style or functional casting.

Syntax to convert int x = 60 to char c:


Implicit:
int x = 60;
char c = x; // implicit conversion
●​ Explicit:
char c = (char)x; // C-style
char c = static_cast<char>(x); // C++ style

17. Implicit and Explicit Type Conversion


Implicit Conversion Explicit Conversion
Done automatically by compiler Done manually by the programmer
Called type promotion Called type casting
Example: int x = 10; float y = x; Example: float y = (float)x; or float(x)

18. Why Initialize Object Using Constructor?


Constructors:
●​ Automatically initialize object data members
●​ Avoid uninitialized or garbage values
●​ Ensure default, consistent, or user-defined values
●​ Allow overloading for flexibility

PART – B

1.​ llustrate how constructors and Destructors work and analyze the difference between
Constructors and Destructors.
2.​ Class Employee{ String Emp_ Name, emp_ Dept; Int Emp_ No,Basic_ Sal;Float
Salary;}; Initialize the class with user input values for a single employee and calculate
Salary as Initialize the class with user input values for a single employee and calculate
salary as DA+HRA+ Allowance, DA is 20% of Basic_ Sal, Allowance is 5% of Basic_
Sal .Print the Employee Details, Write necessary functions inside class.
3.​ Explain operator overloading with suitable example.
Explain the Friend Function and Friend Class in C++, Analyse the rules involved in
creating friend class or friend functions with suitable example.
4.​ Develop a C++ program to implement a class called BankAccount that has private
member variables for account number and balance. Include member functions to deposit
and withdraw money from the account.
5.​ Explain in detail the various types of Constructors with suitable example.

You might also like