Vous êtes sur la page 1sur 5

How is C++ a higher level of C?

Ans:
C++ is an improved and higher level of C with more features and abilities built in it.

Apart from the regular features of C the other features which C++ possess which makes it
a higher level of C are classes, objects, constructors and destructors, virtual functions,
concept of polymorphism, abstract classes, able to provide access levels like public,
private and protected for members, friend functions, operator overloading, exception
handling and so on.

There are lots more features available in C++ which makes users to have more robust
application built. Thus it is possible for C++ to have all abilities of C in addition to more
features built in it.

1. Describe the principles of OOPS


Ans:
Objects
Classes
Inheritance
Data Abstraction
Data Encapsulation
Polymorphism
Overloading
Reusability

Let us see the concept of each briefly.

Objects:

This is the basic unit of object oriented programming. That is both data and function that
operate on data are bundled as a unit called as object.

Classes:

The concept of class is similar to the concept of structure in C. In other words classes are
the data types on which objects are created. So while a class is created no memory is
allocated only when an object is created memory gets allocated.

Inheritance:

As the name suggests Inheritance is the process of forming a new class from an existing
class that is from the existing class called as base class, new class is formed called as
derived class. This is a very important concept of object oriented programming since this
feature helps to reduce the code size.
Data Abstraction:

By this feature of object oriented programming it is possible to represent the needed


information in program without presenting the details. Also by the feature of data
abstraction it is possible to create user defined data types and thus increase the power of
programming language.

Data Encapsulation:

Data Encapsulation is the process of combining data and functions into a single unit
called class. By this method one cannot access the data directly. Data is accessible only
through the functions present inside the class. Thus Data Encapsulation gave rise to the
important concept of data hiding.

Polymorphism:

The ability to use an operator or function in different ways in other words giving different
meaning or functions to the operators or functions is called polymorphism. Poly refers
many. That is a single function or an operator functioning in many ways different upon
the usage is called polymorphism.

Overloading:

The concept of overloading is also a branch of polymorphism. When the exiting operator
or function is made to operate on new data type it is said to be overloaded.

Reusability:

That is object oriented programming has the feature of allowing an existing class which is
written and debugged to be used by other programmers and there by provides a great time
saving and also code efficiency to the language. Also it is possible to a have the existing
class and adds new features to the existing class as pet the programmers choice.

Thus the object oriented programming features helps the program ad there by users of the
application to achieve increased performance, it saves time of developing the application,
give optimized code for the application, helps in gaining secured applications and there
by helps in easier maintenance.

2. Explain the different forms of Polymorphism.


Ans:

1. compile time polymorphism(function and operator overloading)

2.runtime polymorphism.(virtual functions)


1)compile time polymorphism : this process can be done in the compile time only.

tow types of the compiletime polymorphism

a)operator overloading

b)function overloading

2)runtime polymorphism : this process can be done in the runtime only. by using
pointer to object& virtual funtions and also overriding.

3. What is the use/advantage of function overloading


Ans:
the use of function overloading is to save the memory space,consistency and readabiliy.

4. while copying the objects if you say X a = b and asssume that '=' operator is
overloaded then what it will call, a copy constructor or operator overloading function

5. what is the difference between encapsulation and datahiding.explain with example

6. what do you mean by realization in oops, what is presistent,transient object.

7. what is the default sizes of String and StringBuffer?


Ans: string objects are constants & immutablestring Buffer objects are not constants &
growable

1. Strings are immutable where as stringbuffer are not

2. StringBuffer.append() gives better perfomance than string if the concationation at


runtime (Runtime resuliton).

+ operator between strings gives much better performance than StringBuffer.append()


when it is compile time resolution

Run time resolution takes place when the value of the string is not known in advance
where as compile time resolution happens when the value of the string is known in
advance

3. Some intersting things about String Buffer

StringBuffer maintains a character array internally.The default capacity is 16 characters.


When the StringBuffer reaches its maximum capacity, it will increase its size by twice the
size plus 2 ( 2*old size +2).
If you use default size, initially and go on adding characters, then it increases its size by
34(2*16 +2) after it adds 16th character and it increases its size by 70(2*34+2) after it
adds 34th character. Whenever it reaches its maximum capacity it has to create a new
character array and recopy old and new characters. It is obviously expensive. So it is
always good to initialize with proper size that gives very good performance.

8. what is the similarities between macro and function

Ans:

Macro works similar to a function, but it's execution time is faster than function. Also,
macro simply substitutes the value without performing calculatons where as function
does calculations. The following example describes the difference between macro and
function:

Macro:

#define sq(x) x*x

if you call sq(5+5), the result will be 35 becos macro directly substitutes the value. i.e, in
this case, 5+5*5+5 = 35.

Function:

int sq(x)

return x*x;

if you call sq(5+5) now, the result will be 100, because function calculates the argument
value (if it has some calculations) and passes to the operation stack. i.e, in this case
sq(5+5) will become sq(10) before passing to return x*x.

A MACRO CAN CALL ANOTHER MACRO WITH IN ITS DEFINITION, PRETTY


MUCH LIKE IN FUNCTIONS.

#define sq(x) x * x; // finds square of 'x'


#define cu(x) sq(x) * x; // finds cube of 'x'

Here a macro calls another macro, which is strticly possible. The similarity in functions
could look like this.
int sq(int x) { return ( x * x ); }
int cu(int x) { return ( sq ( x ) * x ); }

would be a valid equivalent set of statements that could do the same functionality as that
of above macros.

9. What are these three elements typing, persistence, and concurrency in oop approach
while studying system analysis and design?

Ans:

TYPING:
Identifies a programming language type conversion and characteristics.
For instance, strong typing means that conversions between different data types in
expressions require explicit conversions.
Typing is inherently Language Implementation Dependent

CONCURRENCY:
In distributed architectures, objects can be distributed across multiple processors.
Since they are no longer controlled by a single process (program), their operations, states,
and interactions must be controlled and coordinated in order to avoid resource contention
and processing deadlocks.
Object Synchronization is Part of Distributed Objects

PERSISTENCE:
In distributed architectures or database applications, as a process terminates, the state of
critical objects associated with the terminated process must be stored in a database or in a
file.
This provides persistence, i.e. objects from other processes can reactivate and interact
with the persistent objects without loss of information.
How Objects / Agents Live is Part of Distributed Objects

10. can we create a object of Base class?..


If we can not create a object of base class then why we need Abstract class?

Vous aimerez peut-être aussi