0% found this document useful (0 votes)
8 views2 pages

Object Oriented

Uploaded by

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

Object Oriented

Uploaded by

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

1. Derived class pointer cannot point to base class.

DerivedClass* ptr3 = new DerivedClass(); // pointer to derived class


DerivedClass* ptr4 = new BaseClass(); // error: cannot convert from base class to
derived class

2. Friend Class and Function in C++ : A friend class can access private and
protected members of other classes in which it is declared as a friend.
, and they are not the member of the class .

3.Virtual functions :
A virtual function is a member function declared in a base class and re-declared in
a derived class (overridden). You can execute the virtual function of the derived
class when you refer to its object using a pointer or reference to the base class.
The concept of dynamic binding is implemented with the help of virtual functions.

4. Abstract class
An abstract class is a restricted class that cannot be used to create objects.

5. Objects of any class cannot be made a friend of any other or same class whereas
functions, classes and operator functions can be made a friend.

6. Encapsultion is the concept of binding data and methods and preventing it from
unauthorized access.
Abstraction Example: CAR – the driver of the car only needs to know how to drive
it. Not how its engine and the gear box and other internal components work.

Encapsulation Example: A bank can be thought of as a fully encapsulated class that


provides access to the customers through various methods (getters and setters).
Rest of the data inside bank is hidden to protect from outside world.

Abstraction is process of hiding the implementation details and showing only the
functionality to the users.

Encapsulation is a process of binding data and methods together in a single unit,


providing controlled access to data.

7. Composition is a type of association meaning one class “contains” another.


Association can be viewed as describing a “uses-a” relationship where an object
uses, or in any way interacts with, another object.

8.In C++, constructor cannot be virtual, because when constructor of a class is


executed there is no virtual table in the memory, means no virtual pointer defined
yet. So, the constructor should always be non-virtual.

But virtual destructor is possible.

9. All function calls are resolved at compile-time in Procedure Oriented


Programming

10.An object is an instance of a class i.e. an object represents a class i.e. what
class has(data members) and what it can do(member functions).

11.A class without a name will not have a destructor. The object is made so
constructor is required but the destructor is not.

12.Though C does not allows member functions in structures but C++ allows
structures to have member functions. Members of structures are public by default
and those of classes are private by default. Classes can have protected data
members.

13. Explicit call to a constructor can let you create a temporary instance. This is
because the temporary instances doesn’t have any name. Those are deleted from
memory as soon as their reference is removed.
Implicit calls: The compiler might implicitly call a default constructor (if
available) when you declare an object without arguments. However, these are not
temporary instances as they are assigned to a variable.

Explicit calls: You explicitly use the new keyword followed by the constructor name
and arguments to create a new object. This is the most common way to create
temporary objects.

Copy constructors: These constructors are used to create a copy of an existing


object. They are not typically used for temporary instances.

Therefore, only an explicit call to a constructor allows you to create a temporary


instance that isn’t assigned to a variable and exists momentarily within the
expression or statement.

14. Compiler runs out of memory. This is because while passing the argument by
value, a constructor of the object will be called. That in turn called another
object constructor for values, and this goes on. This is like a constructor call to
itself, and this goes on infinite times, hence it must be passed by reference, so
that the constructor is not called.

You might also like