Home | | Object Oriented Programming | Important Questions and Answers: Basic Characteristics of OOP

Chapter: Object Oriented Programming(OOP) : Basic Characteristics of OOP

Important Questions and Answers: Basic Characteristics of OOP

Object Oriented Programming(OOP) - Basic Characteristics of OOP - Important Questions and Answers: Basic Characteristics of OOP


1. What do you mean by object?

 

Objects are basic run-time entities in an object-oriented system. They may represent a person, a place, a bank account, a table of data or any item that the program has to handle. Each object has the data and code to manipulate the data and theses objects interact with each other.

 

2. What is meant by Encapsulation?

 

The wrapping up of data and function into a single unit(class) is known as Encapsulation. 3. What do you mean by Data abstraction?

 

Abstraction refers to the act of representation of essential features without including the background details or explanations. Classes use the concept of abstraction & are defined as a list of abstraction attributes such as size, weight & cost & functions to operate on these attributes.

 

4. What do you mean by inheritance?

 

Inheritance is the process by which objects of one class acquire the properties of objects of another class.

 

5. What do you mean by reusability?

 

The process of adding additional features to an existing class without modifying it is known as „Reusability . The reusability is achieved through inheritance. This is possible by deriving a new class from an existing class. The new class will have the combined features of both the classes.

 

6. What do you mean by destructor?


clean up storage. Ex., ~integer ( ) { }

 

7. Write some special characteristics of constructor

They should be declared in the public section

They are invoked automatically when the objects are created

8. List the difference between constructor and destructor?

 

Constructor can have parameters. There can be more than one constructor. Constructors is invoked when from object is declared.

 

Destructor has no parameters. Only one destructor is used in class. Destructor is invoked up on exit program.

 

9. How do you allocate / unallocated an array of things?

Use “p = new T(n)” for allocating memory and “delete( ) p” is for releasing ofallocated memory.

Here p is the array of type T and of size n.

Example:

Fred*p=new Fred[100]; // allocating 100 Fred objects to p

...

delete[]p; //release memory

 

Any time we allocate an array of objects via new , we must use [] in the delete statement. This syntax is necessary because there is no syntactic difference between a pointer to a thing and a pointer to an array of things.

 

10. Can you overload the destructor for class?

 

No. You can have only one destructor for a class. It's always called Fred::~Fred( ). It never takes any parameters, and it never returns anything. You can't pass parameters to the destructor anyway, since you never explicitly call a destructor.

 

11. What is the advantage of using dynamic initialization?

 

The advantage of using dynamic initialization is that various initialization formats can be provided using overloaded constructor.

 

12. Define operator overloading?

 

A language feature that allows a function or operator to be given more than one definition. For instance C++ permits to add two variables of user defined types with the

 

same syntax that is applied to the basic types. The mechanism of giving such special meaning to an operator is known as operator overloading.

 

13. Give the operator in C++ which cannot be overloaded?

i. Sizeof ->size of operator

ii. :: ->scope resolution opertor

iii. ?: -> conditional operator

iv.. ->Membership operator

 

v. .* ->pointer to member operator 14. How can we overload a function?

 

With the help of a special operator called operator function. The general form of an operator function is:

 

Return type class name :: operator op(arg list) { Function body }

 

15. Give any four rules for operator overloading?

(i) Only existing operators can be overloaded.

 

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

 

(iii) We cannot used friend functions to overload certain operators.

 

(iv) Overloaded operators follow the syntax rules of the original operators. 16. What are the steps that involves in the process of overloading?


17.            What are the restriction and limitations overloading operators? Operator function must be member functions are friend functions. The

 

overloading operator must have atleast one operand that is of user defined datatype.

18.            Give a function overload a unary minus operator using friend function?

 

frinend void operator –(space &s)

19. List the difference between constructor and destructor?

 

Constructor can have parameters. There can be more than one constructor. Constructors is invoked when from object is declared.

 

Destructor have no parameters. Only one destructor is used in class. Destructor is invoked up on exit program.

 

20. Define Class?

A class is a collection of objects of similar type.

The classes are user defined data types and behave like built in types of a programming language.

A classes is a way to bind the data and its associated unctions together.

A class is a user defined data type with a template that serves to deine its properties

A class is a blueprint that deines the variables and the methods common to all objects of a certain kind.


21. Define polymorphism?

 

Polymorphism means the ability to take more than one form. For example, an operation may exhibit different behavior in different instances. The behavior depends upon the types of data used in the operation.

 

Example: Consider the operation of addition.

For two numbers, the operation will generate a sum.

For two strings, the operation will generate a concatenation.

There are two types of polymorphim: Compile time polymorphism and Run time polymorphism

22. Define Compile time polymorphism / Early Binding / static Binding

 

Compile time polymorphism is implemented by using the overloaded functions and overloaded operators.

 

The overloaded operators or functions are selected for invokation by matching arguments both by type and number. This information is known to the compiler at the compile time therefore the compiler is able to select the appropriate function for a particular function call at the compile time itself. This is called as „Early Binding or „Static Binding or „Static Linking or

 

„Compile time polymorphism . Early binding simply means an object is bound to its function call at the compile time.

 

23. Define Runtime Polymorphism?

 

At runtime, when it is known what class objects are under consideration, the appropriate version of the function is invoked. Since the function is linked with a particular class much later after its compilation, this process is termed as „late binding . It is also known as dynamic binding because the selection of the appropriate function is done dynamically at run time. This runtime polymorphism can be achieved by the use of

 

pointers to objects and virtual functions.

 24. What do you mean by message  passing?

 

Objects communicate with one another by sending and receiving information. A message for an object is a request for execution of a procedure, and therefore will invoke a function in the receiving object that generates the desired result. Message passing involves specifying the name of the object, the name of the function and the information to be sent.

 

25. List out the benefits of OOPS.



27. What is an expression?

 

An expression is a combination of operators, constants and variables arranged as per rules of the language. It may include function calls which return values.

 

28.            What are the different memory management operators used in C++? The memory management operators are new and delete.

 

The new and delete operators are used to allocate and deallocate a memory respectively. 

General form of new : Pointer-variable = new datatype;

 

General form of delete: delete pointer-variable;

29.            What is the general form of a class definition in C ++

Class class_name

{

Private:

 

Variable declaration; Function declaration; Public:

 

Variable declarations; Function declarations; };

 

30. Differentiate Structure and Classes Structures Classes

 

1. By default the members of the structure are public. 1.By default the members of Class are

 

private.

 

2. Data hiding is not possible 2.Data hiding is possible 3.sturcture data type cannot be treated like built-in-type 3.Objects can be treated like built-intypes

 

by means of operator overloading. 4.Structure are used only for holding data

 

4. Classes are used to hold data and functions

 

5.Keyword „struct 5.Keyword „class

 

31. How objects are created?

 Once a class has been declared, we can create variables of that type by using the class name .The class variables are known as objects .The necessary memory space is allocated to an object at the time of declaration.

 

32. How the members of a class can be accessed?

 

The private data of a class can be accessed only through the member functions of that class. The format for calling a member function:

 

Objectname.function_name(actual _arguments);

 

33.                        What are the two ways of defining member functions? Member functions can be defined in two places

Outside the class definition

Inside the class definition

34.Explain about ‘static’ variables.

The special characteristics of static member variable are –

it is  initialized to zero when the first object of its class is created.


Only one copy of that member is created for the entire class, no matter how many objects are created.


It is visible only within the class, but its lifetime is the entire program.

35 Explain about static member functions.

A member unction can have access to only other static members declared in the same class

A static member unction can be called using the class name as follows.

Classname :: function name;

36. What are the ways of passing objects as function arguments?

 

Pass by value : A copy of the entire object is passed to the function. Any changes made to the object inside the function dont affect the objects used to call the function.

 

Pass by Reference: Only the address of the object is transferred to the function. When an address of the object is passed, the called function works directly on the actual object used in the call. This means that any changes made to the object inside the function will reflect in the actual object.

 

37. What are constant arguments?

 

The qualifier const tells the compiler that the function should not modify the argument. The compiler will generate an error when this condition is violated.

 


Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
Object Oriented Programming(OOP) : Basic Characteristics of OOP : Important Questions and Answers: Basic Characteristics of OOP |


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2024 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.