CSE SOLUTION SITE



Object Oriented Programming(OOP)/C++ Question List | Solve

When an operator is overloaded, does it lose any of its original functionality?

An operator is overloaded, does it lose any of its original functionality :


 An operator we specify what it means in relation to the class to which the operator is applied. This is done with the help of a special function, called operator function, which describes the task. The general form of an operator function is:

Return type class-name :: operator op(arglist)
{
                     Function body       //task defined
}
 






Where return type is the type of value returned by the specified operation and op is the operator being overloaded.

Although the semantics of an operator can be extended, we cannot change its syntax, the grammatical rules that its use such as the number of operands, precedence and associativity. Same when a operator is overloaded its original meanings is not lost. For instance, the operator +, which has been overloaded to add two vectors, can be used to add two integers.
 


What do you mean by virtual function? How does a virtual function help to achieve run time polymorphism? Virtual function, How does a virtual function help to achieve run timepolymorphism ?

virtual function? How does a virtual function help to achieve run time polymorphism? Virtual function, How does a virtual function help to achieve run timepolymorphism :


 A virtual function is essentially a function that is declared in base class and redefined by a derived class. Thus by making the base pointer to point to different objects, we can execute different versions of the virtual function.



A virtual function supports runtime polymorphism through the use of base class pointer to points to an object of derived class containing a virtual function, the specific function called is determined by the type of object being pointed to.


When a base class is inherited as public by the derived class? What happens to its public members? What happens to its private members? If the base is inherited as private by the derived class, what happens to its public & private members?

A base class is inherited as public by the derived class? What happens to its public members? What happens to its private members? If the base is inherited as private by the derived class, what happens to its public & private members :


When we need all public members of the base class be as public members of the derived class, then base class is inherited as public by the derived class.

When it is inherited on that way, public members of base class become public members of the derived class and therefore they are accessible to the object of the derived class.

And if it is inherited as private, the public members of the base class become private members of the derived class and therefore they can only be accessed by the member functions of the derived class.

In both cases, private members are not inherited and therefore they will never become the members of its derived class.


What is the Difference between Overriding and overloading?

The difference between Overriding and overloading :


Overloading:
Overloading is defining functions that have similar signatures, yet have different parameters.
Overriding is only pertinent to derived classes, where the parent class has
defined a method and the derived class wishes to override that function. Overriding Overloading
Methods name and signatures must be same. Having same method name with different Signatures. Overriding is the concept of runtime polymorphism Overloading is the concept of compile time polymorphism When a function of base class is redefined in the derived class called as Overriding Two functions having same name and return type, but with different type and/or number of arguments is called as Overloading It needs inheritance. It doesn't need inheritance. Method should have same data type. Method can have different data types Method should be public. Method can be different access specifies.

Example
Overloading
int add(int a, int b)
int add(float a , float b)

Overriding:

public class MyBaseClass
{
public virtual void MyMethod()
{
Console.Write("My BaseClass Method");
   }
}
public class MyDerivedClass : MyBaseClass
{
public override void MyMethod()
{
Console.Write("My DerivedClass Method");
   }
}


What are the difference between function overloading and operator overloading?

The difference between function overloading and operator overloading :


Function Overloading
Operator Overloading
Using same function name to create functions that performs a variety of different tasks is known as function overloading.
C++ has the ability to provide the operators with a special meaning for a data type. The mechanism of giving of such special meaning to an operator is known as operator overloading.
With the help of function overloading, we can design a family of function with one function name but with different argument list.
Operator overloading provides a flexible option for the creation of new definitions for most of the C++ operators.
It is used for using the same function to create function that perform a variety of different task.
It is used to provide arithmetic operation in two variables of user defined types with the same syntax that is applied to the basic types.
The correct function to be invoked is determined by checking the number and type of the arguments but not on the function type.
When return-type is the type of value returned by the specified operation and op is the operator being overloaded.


Differentiate between constructor and destructor.

Differentiate between constructor and destructor :


Constructor
Destructor
A constructor enables an object to initialize itself when it is created.
A destructor destroyed the objects that have been created by a constructor.
Its name is the same as the class name.
Its name is the same as the class name but is preceded by a ~ .
It allocates memory space
It releases memory space.
A constructor can take arguments.
A destructor never takes any arguments.
It will be invoked whenever an object of its class is created.
It will be invoked by compiler upon exit from the program to clean up the storage


What are the striking features of object oriented programming?

Some of the striking features of object oriented programming are:


* Emphasis is on data rather than procedure.

* Programs are divided into what are known as objects.

* Data structures are designed such that they characterize the object.

* Functions that operate on the data of an object are tied together in the data structure.

* Data is hidden & cannot be accessed by external functions.

* Objects may communicate with each other through functions.

* New data and functions can be easily added whenever necessary.
 
* Follows bottom up approach in program design.


What are meant by object oriented programming? Give example.

Object oriented programming? Give example :


Object oriented programming treats data as a critical element in the program development and does not allow it to flow freely around the system. OOP allows decomposition of a problem into a number of entities called objects and then builds data and functions around these objects. The data of an object can be accessed only by the functions associated with that object. However, functions of one object can access the functions of other objects.

Object oriented programming is an approach that provides a way of modularizing programs by creating partitioned memory area for both data and functions that can be used as templates for creating copies of such modules on demand. The following figure describes the organization of data and functions in OOP.

Example- C++, Java, Smalltalk.


Data abstraction Vs Data encapsulation.

Data abstraction Vs Data encapsulation :


Abstraction:

Abstraction is about representing something in its essential detail only. Encapsulation, which is closely related to the notion of scope, is about preventing unrestricted access to program state. Both abstraction and encapsulation depend on programming paradigm. In the object-oriented paradigm, for example, abstraction is achieved via decomposition to classes. In the functional paradigm, abstraction is achieved primarily via decomposition to functions.

Encapsulation

Encapsulation is achieved, in the object-oriented paradigm, by restricting variable access only to the methods of the containing class. In the functional paradigm, for example, encapsulation is achieved implicitly by way of the calling convention.


Write down the benefits of OOP

The benefits of OOP :


  • Through inheritence, we can eliminate redundant code and extend the use of existing classes.

  • We can build program the standard working modules that communicate with one another, rather than having to start writing the code from scratch.This leads to saving of development time and higher productivity.

  • The principal of data hiding helps the programmer to build secure programs that cannot be invaded by code in other parts of the program.

  • It is possible to have multiple instance of an object to co-exist without any interference

  • It is possible to map objects in the problem domain to those in the program

  • It is easy to partition the work in a project based on objects

  • The data centered design approach enables us to capture more details of a model in implementation form.

  • Object-oriented systems can be easily upgraded from small to large systems.

  • Message passing techniques for communication between objects makes the interference descriptions with external systems much simpler.

  • Software complexity can be easily managed


Write down the Applications of OOP

The Applications of OOP :


  • real time systems

  • Simulation and modeling

  • Object oriented databases

  • Hypertext, hypermedia, expertext

  • AI and expert systems

  • Neural networks and parallel programming

  • Decision support and office automation systems

  • CIM/CAM/CAD systems


Write down the Applications of C++

The Applications of C++ :


  • Since C++ allows us to create hierarchy-related objects, we can build special object-oriented library which can be used later by many programmers.

  • While C++ is able to map the real-world problem properly, the C part of C++ gives the languages the ability to get close the machine level details.

  • C++ programs are easily maintainable and expandable.When a new feature needs to be implemented, it is very easy to add to the existing structure of an object

  • It is expected that C++ will replace C as a general purpose language in the near future.


Write down the Characteristics of Friend Functions

The Characteristics of Friend Functions :


  • It is not in the scope of the class to which it has been declared as friend

  • Since it is not in the scope of the class, it cannot be called using the object of that class.

  • 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 operator with each member name

  • It can be declared either in the public or the private part of the class without affect in it meaning.

  • Usually, it has the objects as arguments.


Write down the Characteristics of Constructure

The Characteristics of Constructure :


  • 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, and they cannot return values.

  • They cannot be inherited, through a derived class can call the base class constructor

  • Like other C++ functions, they can have default arguments

  • Constaructors cannot be virtual

  • We cannot refer to their addresses

  • An object with a constructor cannot be used as a member of a union

  • They make implicit calls to the operators new and delete when memory allocation is required.


Write down the Rules for the overloading operators

The Rules for the overloading operators :


  • Only existing operators can be overloaded.New operators cannot be created

  • The overloaded operator must have at least one operand that is of user defined type.

  • We cannot change the basic meaning of an operator.That is to say, we cannot redefined the plus(+) operator to substract one volume from the other.

  • Overloaded operators follow the syntax rules of the original operators.They cannot be overridden

  • There are some operators that cannot be overloaded

  • We cannot use friend functions to overload certain operators.How ever, member functions can be used to overload them.

  • Unary operators, overloaded by means of a member function, take no explicit arguments and return no explicit values, but those overloaded by means of a friend function, take one reference argument

  • Binary operators overloaded through a member function take one explicit argument and those which are overloaded through a friend function take two explicit arguments

  • When using binary operators overloaded through a member function, the left hand operand must be an object of the relevant class.

  • Binary arithmetic operators such as +,-,*,and / must explicitly return a value.They must not attempt to change their own arguments.


© Copyright & reserved CSE Solve