Top Banner
CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture No 1: What is Object-oriented programming (OOP)? Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Whereas C++ is a partial implementation of OOP paradigm where you can include features such as data abstraction, encapsulation, messaging, modularity, polymorphism, and inheritance. What are the applications of oop in our professional life? OOP is the basic programming language which is widely used in many other languages. Or we can say that is it the base of many other concepts and emerging technologies. Many modern programming languages extensively used and support OOP. Some of the applications of OOP are: Dynamic programming languages Design patterns Wed application What is difference between Encapsulation and Abstraction? In encapsulation all the characteristics of an object is present in the object itself while in abstraction we capture only those details which are relevant to object current prospective. Read handout as their difference is given in handout with enough details. How can differentiate b/w OOP and OO Model? We make Object Oriented models showing several interacting objects to understand a system given to us for implementation. During coding in object oriented programming approach we have objects with their attributes and behaviors that are hidden from other classes, so we can say that object oriented programming follows the principle of information hiding. Prepared By: Irfan Khan (Chief Admin) Page 1
38

CS304 Lecture Wise Questions by Virtualians Social Networkapi.ning.com/files/T-9GsR3UPPEZ8gV7dQdNJF3Xq0u8... · CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture

Mar 30, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CS304 Lecture Wise Questions by Virtualians Social Networkapi.ning.com/files/T-9GsR3UPPEZ8gV7dQdNJF3Xq0u8... · CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture

CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork

Lecture No 1:

What is Object-oriented programming (OOP)? Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Whereas C++ is a partial implementation of OOP paradigm where you can include features such as data abstraction, encapsulation, messaging, modularity, polymorphism, and inheritance.

What are the applications of oop in our professional life? OOP is the basic programming language which is widely used in many other languages. Or we can say that is it the base of many other concepts and emerging technologies. Many modern programming languages extensively used and support OOP. Some of the applications of OOP are:

Dynamic programming languages Design patterns

Wed application What is difference between Encapsulation and Abstraction?

In encapsulation all the characteristics of an object is present in the object itself while in abstraction we capture only those details which are relevant to object current prospective. Read handout as their difference is given in handout with enough details. How can differentiate b/w OOP and OO Model?

We make Object Oriented models showing several interacting objects to understand a system given to us for implementation.

During coding in object oriented programming approach we have objects with their attributes and behaviors that are hidden from other classes, so we can say that object oriented programming follows the principle of information hiding.

Prepared By: Irfan Khan (Chief Admin) Page 1

Page 2: CS304 Lecture Wise Questions by Virtualians Social Networkapi.ning.com/files/T-9GsR3UPPEZ8gV7dQdNJF3Xq0u8... · CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture

CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork

What is difference between Tangible and Intangible ? Tangible: Something that can be physically touched or felt. For example something real and substantial.

Intangible: Something that cannot be touched. If something is intangible it does not mean it's not real. It just means it has no physical existence like emotions. development

What is a model? A model is an abstraction of something real or conceptual. We need models to understand an aspect of reality. Advantages of Object-Orientation We can easily develop an object oriented model for a problem. Everyone can easily understand an object oriented model. We can easily implement an object oriented model for a problem using any object oriented language like c++ using its features like classes, inheritance, virtual functions and so on.

What is an object? An object is,

1. Something tangible (Ali, School, House, Car).2. Something conceptual (that can be apprehended intellectually for example time, date and so on.).

An object has, 1. State (attributes)2. Well-defined behavior (operations)3. Unique identity

What is Polymorphism?

it can be described as existence of one entity in more than one form its simplest example is function overloading in c++, where a function can work for more than one data type according to nature of parameters passed to the function.

Prepared By: Irfan Khan (Chief Admin) Page 2

Page 3: CS304 Lecture Wise Questions by Virtualians Social Networkapi.ning.com/files/T-9GsR3UPPEZ8gV7dQdNJF3Xq0u8... · CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture

CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork

Lecture no 2:

Information Hiding:

Showing only those details to the outside world which are necessary for the outside world and hiding all other detail from the out side world.

Key Points in information hiding:

information is stored within the object

Outside World can't have direct access to the information however outside world can ask the object to give information so we can say there is indirect access by the outside world

Encapsulation(closely related to information hiding)

" Data and behavior are tightly coupled inside an object"

In C Function are separate from data while in objects the behavior of entity and state are tightly coupled. Both the information structure and implementation details of its operations are hidden from the out world in encapsulation.

Advantages Of Encapsulation:

Following are some advantage of Encapsulation:

Simplicity and clarity Low complexity Better understanding

As there is no direct to the information in encapsulation so it makes a model simple, easy to understand.

Prepared By: Irfan Khan (Chief Admin) Page 3

Page 4: CS304 Lecture Wise Questions by Virtualians Social Networkapi.ning.com/files/T-9GsR3UPPEZ8gV7dQdNJF3Xq0u8... · CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture

CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork

Separation of interface and implementation: Changes in information does not affect the object interface. this is achieved via principles of information hiding and encapsulation.

Messages: Objects communicate with each other through messages. message is a terminology used in object oriented programming.

object send message by invoking appropriate operations on the target object.

We can say message activate the interface

Data Hiding: Information is stored within the object. It is hidden from the outside world. It can only be manipulated by the object itself. All of these are the known principles of OOP paradigm.

What is difference b/w characteristic, behavior and interface?

All these concepts are very related to each other. Characteristics is a general word that most often represents the state/data related to any specific object, like Age, size, color etc. but sometimes it also indicates the features related to any specific object depends upon the scenario,,,,,, e.g. eat(), play() etc

As for as concerns the behavior of an object, its definitely the functions owned by that particular object. For example, your course selection() process is a behavior related to you (object).

Now, Messages stimulates interfaces. For example a car has hidden information how to change the Gear internally from end users, but driver/ user of the car access that hidden information/service through well defined interface i.e. “by moving back and forth, around the liver”.

What “barrier against change propagation” means? It’s an advantage of information hiding that it makes difficult to change the sate of object, while one has to access only that part of object for which it gives access.

Prepared By: Irfan Khan (Chief Admin) Page 4

Page 5: CS304 Lecture Wise Questions by Virtualians Social Networkapi.ning.com/files/T-9GsR3UPPEZ8gV7dQdNJF3Xq0u8... · CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture

CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork

So, “barrier against change propagation” means to stop irrelevant changes in an object state.

What is difference between interface ,encapsulation and implementation? Encapsulation: Encapsulation means data and behavior are tightly coupled both the information structure and implementation detail of its operations are hidden from the outer world.

Interface: When one object wants to interact with another object they communicate with their interfaces. Let take an example of a car when we want to stop car (operation) there is an interface of break paddles through which we stop the car.

Implementation: Implementation means, provides services offered by the object interface, in simple words, practically coding these concepts in programming language called implementation.

Lecture no 3:

What is Information Hiding?

Information hiding means to show only the relevant details to outside world and hide irrelevant details from outside world. For example, to give input to computer, you use keyboard; means you are not aware from the details that how the information is being input/stored in the computer. You just use this interface (i.e. keyboard) to input your data while rest of the details are hidden from you. In object oriented paradigm, encapsulation is a way to achieve the concept of information hiding. It encapsulates data and functions into a single unit. Difference between Abstraction ad Class?

Abstraction Real life objects have a lot of attributes and much kind of behaviors but most of the time we are interested in only that part of the objects that is related to the problem.

Let take an example of a student in a school, when we consider it as an object in a school system we don’t need the personal detail of student (Ali) we just take the behaviors and characteristics related to the school.

Prepared By: Irfan Khan (Chief Admin) Page 5

Page 6: CS304 Lecture Wise Questions by Virtualians Social Networkapi.ning.com/files/T-9GsR3UPPEZ8gV7dQdNJF3Xq0u8... · CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture

CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork

Classes

A class is the physical structure of objects, for example, we have objects like, Ali, Asad and Saad in a University environment. All of these are students and studying different subjects.

We make (Define) a class of students and all of them put together and named as class student.

What is the concept of "Less Redundancy" and "Increased maintainability" please with the example of real life ? Less redundancy and increases maintainability are two of the advantages of inheritance.

See the example given below to understand the concept of “Less redundancy”.

Example: Suppose you have a class of Person with attributes name, age, and behaviors eat() and walk(). Now, we want to create another class “Scientist” with attributes name, age, Specialization Field and behavior eat (), walk (), experiment (). If we don’t use the concept of inheritance, we will have to write name, age, eat () and walk () again in Scientist class resulting in redundant information.

On the other hand, if we use the concept of inheritance here, we will write only those details i.e. attribute SpecializationField and behavior experiment () that are related to Scientist class while inherit other attributes and behavior from Person class. Thus information will not be written again, and redundancy will be reduced.

Now, for other advantage; in maintenance phase, if you want to make some changes to eat (), walk () or any other common method of Person class, you will only change methods of Person class and that change will automatically be made in all derived classes such as Scientist etc. Thus, maintainability will be increased.

Lecture no4:

What is the diagram of Specialization ?

Specialization means that derived class is behaviorally incompatible with the base class

Behaviorally incompatibility means that base class can’t always be replaced by the derived class

Prepared By: Irfan Khan (Chief Admin) Page 6

Page 7: CS304 Lecture Wise Questions by Virtualians Social Networkapi.ning.com/files/T-9GsR3UPPEZ8gV7dQdNJF3Xq0u8... · CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture

CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork

Derived class has some different of restricted characteristics than of base class.

What is the Sub typing ?

Sub typing and generalization are related concepts, Subtyping (extension) and generalization is a way to look same thing in two ways.

Sub typing is looking at things from Top to bottom whereas in generalization we look at things from bottom to top.

What is the Generalization?

A class containing common features for all other classes to be inherited. Generalization is the process of extracting shared characteristics from two or more classes, and combining them into a generalized superclass. Shared characteristics can be attributes, associations, or methods.

What is Restriction ? Restriction is a process in which derived class inherits base class characteristics and then applies some restriction on base class method while Overriding concept is related with inheritance. In overriding child class gives a new implementation to a derived method by either extending its behaviour or restricting its behavior.

What is use of overriding? Overriding concept is related with inheritance. In overriding child class gives a new implementation to a derived method by either extending its behavior or restricting its behavior while in concrete class represents a concrete concept; we can only instantiate an object of concrete object.

It is used to provide specialization, extension, restriction and to improve performance.

what is the relation between abstract class and generalization?

Abstract class and generalization are related concepts. Abstract class is a class, whose object can not be instantiated. Through inheritance we convert Abstract classes into concrete classes which can then be instantiated. Abstraction reduces complexity by hiding irrelevant details, while generalization reduces complexity by replacing multiple entities which perform similar functions with a single construct.

Prepared By: Irfan Khan (Chief Admin) Page 7

Page 8: CS304 Lecture Wise Questions by Virtualians Social Networkapi.ning.com/files/T-9GsR3UPPEZ8gV7dQdNJF3Xq0u8... · CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture

CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork

Example: Person class is an abstract class; through inheritance we can derive some specialized classes like, teacher, student, Doctor, etc, having some general characteristics of base class.

What are Concrete Classes?

Concrete classes are those classes whose objects can be instantiated. Examples: Student, Teacher, Doctor, Circle, Triangle etc are concrete classes, whose objects can be instantiated. Student Std; Teacher Tch; Doctor Dr;

What is the difference between oop and procedural programming?

These two are of different approaches of software development. Both have some advantages and disadvantages over each others. OOP uses and sees everything in terms of "Object". You know that in OOP an object has some characteristics, behavior and unique ID.OOP is very close to real world scenario and easy to model as compared to procedural approach. When an organization decides to develop an application by using OOP approach, then, definitely analysis and design of that particular application will be developed by using OOA/D concepts. All these concepts , you will study in detail in Software Engineering course. However, major components of OOP that makes it different from Procedural programming is as follows:

Abstraction, Encapsulation, Inheritance, Coupling, Cohesion, Information hiding, Aggregation, Composition, Association etc.

What is the difference between overriding and abstraction?

You know that in inheritance, derived class has right to own all the data and behaviour of its base class. It is seen practically that there might be at least one situation among the four listed below while in inheritance under the concept of Overriding a function.

Prepared By: Irfan Khan (Chief Admin) Page 8

Page 9: CS304 Lecture Wise Questions by Virtualians Social Networkapi.ning.com/files/T-9GsR3UPPEZ8gV7dQdNJF3Xq0u8... · CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture

CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork

1- Derived class uses the override function as it is from base class 2- Derived class extends somehow the behaviour of Overrided function as per its needs 3- Derived class restrict somehow the behaviour of Overrided function as per its needs.

Abstraction is different from that one in such a way that it "Abstraction is used to minimize the complexity of the system by binding up the relevant data and behavior together.

What is concert class ?

Almost all classes we studied so far are concrete classes, by concrete class we mean such class for which we can create objects. However in coming lectures of this course we will study Abstract classes which are conceptual parent classes for child classes, then the difference of concrete and abstract class will become clearer

What is Generalization?

Generalization is the process of extracting shared characteristics from two or more classes, and combining them into a generalized superclass. Shared characteristics can be attributes, associations, or methods. In class diagrams, a generalization relationship, which is also called an inheritance or an is-a relationship, implies that a specialized, child, class is based on a general, parent, class. Generalization implies an "is a" relationship. One class is derived from another, the base class. Generalization is implemented as inheritance in C++. The derived class has more specialization. It may either override the methods of the base, or add new methods

Lecture No 5:

What are Abstract classes?

Abstract classes are used to fulfill abstract concepts in our model like (shape, person), we cannot make any object of this (abstract) class. It can only be used as a parent (in hierarchy) for derived classes that inherits from the abstract class.

Abstract Classes cannot exists standalone in an object model as it allows you to define a problem into imaginary classes that are not fully defined; therefore abstract classes cannot exists standalone in a model, there will definitely exist some concrete classes as well which are derived from this abstract class otherwise there is no use of abstract class.

Prepared By: Irfan Khan (Chief Admin) Page 9

Page 10: CS304 Lecture Wise Questions by Virtualians Social Networkapi.ning.com/files/T-9GsR3UPPEZ8gV7dQdNJF3Xq0u8... · CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture

CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork

Objects are also called instances of a class as they are used to instantiate a class in a program.

What is class association? And what is public and private inheritance described in class association?

We implement class association in terms of Inheritance. You are already studied that Inheritance is used to implement generalization/specialization relationship between objects. Inheritance can be of three types: public inheritance, private inheritance and protected inheritance. Class association in case of public inheritance is “IS-A” relationship and in case of private inheritance it is “Implemented in terms of” relationship. In case of public inheritance public members of base class become public members of derived class. And in case of private inheritance public members of base class become private members of derived class

Why association is used in programming?

In an object model, usually all objects interact with all other objects. So programming requires Association. As OOP programming models the real world where all objects needs some services to other objects. So association is required in real world as well as in OOP.

What is orientation inherence?

Object orientation is a way we think our programming solutions in terms of real life objects and relationship among them. There are many concepts which have been originated in Object Oriented Progamming. We think each and every entity / concept in terms of object when we talk about object oriented programming.

Now when we talk about inheritance in objects and classes in programming this is exactly the real life phenomena of object orientation. Similar like in our families there is a relationship between parent objects and child objects same is the case in the programming phenomena. We take everthing as object or class to deal with. So inheritance is a feature of object oriented programming.

What is cop and complexity?

Cope means handle, manage, deal with etc Complexity means difficulty, complication etc

Prepared By: Irfan Khan (Chief Admin) Page 10

Page 11: CS304 Lecture Wise Questions by Virtualians Social Networkapi.ning.com/files/T-9GsR3UPPEZ8gV7dQdNJF3Xq0u8... · CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture

CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork

Complexity increases without abstraction: Without abstraction all the data (either relevant or irrelevant) will store, and all the functionality will be implemented, which increased the complexity of program. And using abstraction only relevant data will be stored, minimizing the complexity of program.

What is domain?

Domain represents any specific field/area. Domain knowledge means knowledge/ information/ data about any particular area. If a person has knowledge about a particular field, he is called “Domain Expert” of that field.

Example: If “Ali” is expert in “Network Security”, then his domain is “network security”.

What is the main difference between Two way and Binary Association?

In binary association two entities are involved but association between these entities may be one way or two way. But in two way association two entities are involved but association between these entities must be two way. One way association is represented with an arrow, while two way association is represented by a line.

What is the value of cardinality(*) in association?

Cardinality is a rule specifying how many times an entity can be related to another entity in a given relationship. "*" means many i.e. an entity can be related to another entity many times.

Example: Company and Employees: Many employees can related with a single entity i.e. company

What is “is a” relationship?

The “is a” or “is a kind of” relationship between two classes is represented in object oriented programming through “inheritance”.

Prepared By: Irfan Khan (Chief Admin) Page 11

Page 12: CS304 Lecture Wise Questions by Virtualians Social Networkapi.ning.com/files/T-9GsR3UPPEZ8gV7dQdNJF3Xq0u8... · CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture

CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork

Examples: “Triangle” is a “Shape” or “Triangle” is a kind of “Shape”. “Student” is a “Person” or “Student” is a kind of “Person”. “CS304” is a “Subject” or “CS304” is a kind of “Subject”.

In all of the above examples there is a relationship of “is a” or “is a kind of” between these classes. So while coding, we should mention “inheritance” relationship between these classes.

What is the * of the one way direction?

“*” represents many instance of an entity that can be related with other entity.

Examples: Ali drives many cars. A teacher teaches to many students.

A single instance of Ali can be related with many instances of car. A single instance of teacher can be related with many instances of students.

what is definition , declaration and initialization ?

A declaration is a statement that says "here is the name of something and the type of thing that it is, but I'm not telling you anything more about it".

A definition is a statement that says "here is the name of something and what exactly it is". For functions, this would be the function body; for global variables, this would be the translation unit in which the variable resides.

An initialization is a definition where the variable is also given an initial value. Some languages automatically initialize all variables to some default value such as 0, false, or null. Some (like C/C++) don't in all cases: all global variables are default-initialized, but local variables on the stack and dynamically allocated variables on the heap are NOT

Prepared By: Irfan Khan (Chief Admin) Page 12

Page 13: CS304 Lecture Wise Questions by Virtualians Social Networkapi.ning.com/files/T-9GsR3UPPEZ8gV7dQdNJF3Xq0u8... · CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture

CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork

default initialized - they have undefined contents, so you must explicitly initialize them. C++ also has default constructors, which is a whole nother can of worms.

Examples:

// In global scope: extern int a_global_variable; // declaration of a global variable int a_global_variable; // definition of a global variable int a_global_variable = 3; // definition & initialization of a global variable

int some_function(int param); // declaration of a function int some_function(int param) // definition of a function { return param + 1; }

What is Aggregation?

Aggregation is a form of composition where one looks at the system as a whole rather than as parts. It is also based on has-a relationship and is implemented by creating objects of other classes inside the class. An example will be a car class which is an aggregation of different classes like wheel, engine, body etc.This may be explained with the help of an example. Suppose you have a class named User Information . And with that class you are having a object instance named UserContactInfo

Class UserInformation {

UserContactInfo userContactInfo ;

}

This leads to aggregation. The UserContactInfo object is aggreated within UserInformation class. Both the classes have individual identity.

Prepared By: Irfan Khan (Chief Admin) Page 13

Page 14: CS304 Lecture Wise Questions by Virtualians Social Networkapi.ning.com/files/T-9GsR3UPPEZ8gV7dQdNJF3Xq0u8... · CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture

CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork

Now suppose we have a class named Rectangle . And within that class you have Class Point as a object.

Class Rectangle {

Point point ;

}

Now rectangle is a composition of points. Point class doesn't have any individual important . It is point that makes a rectangle . This is known as composition

What are Advantages and Disadvantages of Multiple Inheritance ?

Advantages: It reduces the Code of a class and use their function without to write them again

Disadvantages:

Increase Complexity

Reduce Understanding

Duplicate feature

Q:How many Types of Association?

class Association Object Association

Prepared By: Irfan Khan (Chief Admin) Page 14

Page 15: CS304 Lecture Wise Questions by Virtualians Social Networkapi.ning.com/files/T-9GsR3UPPEZ8gV7dQdNJF3Xq0u8... · CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture

CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork

WHAT IS COMPOSITION?

It is a strong ownership of the part by the whole ,For example:A person has a strong relationship with his head ,,where head is a composition relationship

What is Association?

It Is a structural relationship which represents a binary relationship between a class.

What is aggregation?

Relationship between container and contained object.

It is weak due to:

aggregated object is not a part of container and the object can exist independently

Lecture no 6

What are Advantages of information hiding?

It’s an advantage of information hiding that it makes difficult to change the sate of object, while one has to access only that part of object for which it gives access.So, “barrier against change propagation” means to stop irrelevant changes in an object state.

Two way association?

Yes in two way association we can navigate in both directions, so there is no arrow mentioned in this association as both objects can act as a server object.

You are confused in label of association, so dear student make it clear that label of association is changed with respect to server object in this association.

“Employee works for company” and “Company employs employees” are two different aspects of the same association.

Prepared By: Irfan Khan (Chief Admin) Page 15

Page 16: CS304 Lecture Wise Questions by Virtualians Social Networkapi.ning.com/files/T-9GsR3UPPEZ8gV7dQdNJF3Xq0u8... · CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture

CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork

In first case of this association, company act as a server object and in second case employees act as server object. So that label of associations may change according to the services of objects.

What is difference between overloading and overriding?

The main difference between overloading and overriding is that in overloading we can use same function name with different parameters to perform multiple tasks on the basis of parameters with in a class. Overriding means we can use same function name with same parameters in base and derived class. Base class only declares the function but derived class implements the function.

Can we use UML for developing any object oriented model? An object is a self-contained entity with well-defined characteristics and behaviors while the characteristics and behaviors are represented by attributes and operations respectively. A class is a generic definition for a set of similar objects. Hence, an object is an instance of a class. An object model provides a static conceptual view of an application. It shows the key components (objects) and their relationships (associations) within the application system. The object model is drawn using UML notations.

What is Polymorphism?

Polymorphism in simple words can be defined as" Single Interface Multiple Behavior". poly means many morph means shapes so, one function taking many shapes ,for ex: take the function name as add, by passing different sets of arguments it can add 2no.s,3 numbers etc.... there are two types of polymorphism namely, runtime polymorphism, compile time polymorphism, compile time Polymorphism means function overloading, run time polymorphism means virtual functions.

Prepared By: Irfan Khan (Chief Admin) Page 16

Page 17: CS304 Lecture Wise Questions by Virtualians Social Networkapi.ning.com/files/T-9GsR3UPPEZ8gV7dQdNJF3Xq0u8... · CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture

CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork

What is Pointer?

In C++ or OOP by using C++, we have a "this" pointer. Pointer is used to store the address of any variable/Object. this pointer stores the address of the class instance, to enable pointer access of the members to the member functions of the class. this pointer is not counted for calculating the size of the object. this pointers are not accessible for static member functions. this pointers are not modifiable

What are security and privacy?

Defining "computer security" is not trivial. The difficulty lies in developing a definition that is broad enough to be valid regardless of the system being described, yet specific enough to describe what security really is. In a generic sense, security is "freedom from risk or danger." In the context of computer science, security is the prevention of, or protection against, • access to information by unauthorized recipients, and • intentional but unauthorized destruction or alteration of that information1 This can be re-stated: "Security is the ability of a system to protect information and system resources with respect to confidentiality and integrity." Note that the scope of this second definition includes system resources, which include CPUs, disks, and programs, in addition to information. A feature of a voice mail system that allows a sender to mark a message as private or confidential, thereby denying the recipient the ability to forward it to another user is the privacy.

Class Compatibility? A class is behaviorally compatible with another if it supports all the operations of the other class. Such a class is called subtype. A class can be replaced by its subtype. Derived class is usually a subtype of the base class. It can handle all the legal messages (operations) of the base class. Therefore, base class can always be replaced by the derived class.

Polymorphism in OO Model In OO model, polymorphism means that different objects can behave in different ways for the same message (stimulus). Consequently, sender of a message does not need to know exact class of the receiver.

Sender sends message to receiver and appropriate method is called on receiver side.

Prepared By: Irfan Khan (Chief Admin) Page 17

Page 18: CS304 Lecture Wise Questions by Virtualians Social Networkapi.ning.com/files/T-9GsR3UPPEZ8gV7dQdNJF3Xq0u8... · CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture

CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork

Lecture no 7

What is the difference between constructor and destructor?

Difference between constructor and destructor is given in table form:

Constructor Destructor Same name as class name Same name as class name but preceded by tilde (~) sign Used for memory allocation/ initialization Used for memory de-allocation Constructor automatically called when an object is created Destructor is automatically called when an object is destroyed

What is abstraction?

Abstraction is infact an OOP concept that deals with "Relevancy". Put only relevant information in an object ans remove irrelevancy with in a particular scenario. For example, if you want Student Record that is used by Exam department , So, in this scenario, Exam department doesn't require information about student's brother as they only concern your marks, CGPA Roll No etc. So, putting relevant information as required in a particular scenario is the Abstraction.

What is this pointer ?

this pointer is used as a pointer to the class object instance by the member function. The address of the class instance is passed as an implicit parameter to the member functions. When a class need to access its objects (data members) in any of its functions then it use this pointer to access that data member. Look at the following example to understand how to use the 'this' pointer. class this_pointer_example // class for explaining C++ tutorial {int data1; public: //Function using this pointer for C++ Tutorial int getdata() {return this->data1; }

Prepared By: Irfan Khan (Chief Admin) Page 18

Page 19: CS304 Lecture Wise Questions by Virtualians Social Networkapi.ning.com/files/T-9GsR3UPPEZ8gV7dQdNJF3Xq0u8... · CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture

CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork

void setdata(int data1) { this->data1 = data1; } };

What is "bool" ?

bool or Boolean is a data type in C++. Boolean variables only have two possible values: true (1) and false (0). To declare a boolean variable, we use the keyword bool. bool bValue; When assigning values to boolean variables, we use the keywords true and false. bool bValue1 = true; Just as the unary minus operator (-) can be used to make an integer negative, the logical NOT operator (!) can be used to flip a boolean value from true to false, or false to true:

bool bValue1 = !true; // bValue1 will have the value false When boolean values are evaluated, they actually don’t evaluate to true or false. They evaluate to the numbers 0 (false) or 1 (true). Consequently, when we print their values with cout, it prints 0 for false and 1 for true: bool bValue = true; cout bValue endl; cout !bValue endl; bool bValue2 = false; cout bValue2 endl; cout !bValue2 endl; Outputs: 1001One of the most common uses for boolean variables is inside if statements: bool bValue = true; if (bValue) cout "bValue was true" endl; else cout "bValue was false" endl; Output: bValue was true

Prepared By: Irfan Khan (Chief Admin) Page 19

Page 20: CS304 Lecture Wise Questions by Virtualians Social Networkapi.ning.com/files/T-9GsR3UPPEZ8gV7dQdNJF3Xq0u8... · CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture

CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork

Don’t forget that you can use the logical not operator to reverse a boolean value: Boolean values are also useful as the return values for functions that check whether something is true or not. When converting integers to booleans, the integer zero resolves to boolean false, whereas non-zero integers all resolve to true.

What is domain knowledge?

Domain knowledge means knowledge about specific area. For example; extract properties from the object “line” from the domain knowledge, its mean that extract that properties which are discuss in the given scenario only.

Use of scope resolution?

Scope resolution is used to access a static data member and to define a function outside the class. Example:#include <iostream>using namespace std;

char c = 'a'; // global variable

int main() {

char c = 'b'; //local variable

cout << "Local c: " << c << "\n"; cout << "Global c: " << ::c << "\n"; //using scope resolution operator

return 0;

}

Use of char *?

Where * is used to declare the pointer of a variable and that pointer is used to save the address of another variable.

Prepared By: Irfan Khan (Chief Admin) Page 20

Page 21: CS304 Lecture Wise Questions by Virtualians Social Networkapi.ning.com/files/T-9GsR3UPPEZ8gV7dQdNJF3Xq0u8... · CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture

CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork

Example; char *name will save the address of a character variable

char abc;

name = &abc;

Example:#include <iostream>

using namespace std; int main() { int x; // A normal integer int *p; // A pointer to an integer p = &x; // Read it, "assign the address of x to p" cin>> x; // Put a value in x, we could also use *p here cin.ignore(); cout<< *p <<"\n"; // Note the use of the * to get the value cin.get(); }

Lecture no 8

What is difference member function and public members?

Classes can contain data and functions. These functions are referred to as "member functions." Any function declared inside a class declaration is considered a member function. For example: // member_functions1.cpp // compile with: /EHsc #include <iostream> using namespace std;

Prepared By: Irfan Khan (Chief Admin) Page 21

Page 22: CS304 Lecture Wise Questions by Virtualians Social Networkapi.ning.com/files/T-9GsR3UPPEZ8gV7dQdNJF3Xq0u8... · CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture

CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork

class Point { public:

int i=13;

void Show() { cout "Member function\n"; } };

int main() { Point pt; pt.Show(); } void Show() is a member function of class Point and ‘i’ is a public member of the class. This public member is accessed outside the class while private and protected members are not accessible outside the class.

What is Default Access specified?

Access specifier are keywords (private, protected and public) which are used to set the scope of any variable or function, by default access specifier we mean the default scope used to access the member variables or functions in case we don't mention any access specifier for example in classes the default access specifier is private, same in the case for inheritance, however default access specifier for structures is public as they were used only to group data.

Can we use protected keyword instead of private keyword?

Prepared By: Irfan Khan (Chief Admin) Page 22

Page 23: CS304 Lecture Wise Questions by Virtualians Social Networkapi.ning.com/files/T-9GsR3UPPEZ8gV7dQdNJF3Xq0u8... · CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture

CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork

The protected keyword specifies access to class members in the member-list up to the next access specifier (public or private) or the end of the class definition. Class members declared as protected can be used only by the following: Member functions of the class that originally declared these members. Friends of the class that originally declared these members. Classes derived with public or protected access from the class that originally declared these members. Direct privately derived classes that also have private access to protected members.

protected: [member-list] protected base-class

What is the difference b/w base class & concrete class?

A base class is a class containing all common attributes and behaviors. Whereas concrete class is a class which is not of abstract type and whose object can be created.

What is default constructor?

A default constructor is a constructor that either has no parameters, or if it has parameters, all the parameters have default values.

If no user-defined constructor exists for a class A and one is needed, the compiler implicitly declares a default parameter-less constructor A::A(). This constructor is an inline public member of its class. The compiler will implicitly define A::A() when the compiler uses this constructor to create an object of type A. The constructor will have no constructor initialize and a null body.

Prepared By: Irfan Khan (Chief Admin) Page 23

Page 24: CS304 Lecture Wise Questions by Virtualians Social Networkapi.ning.com/files/T-9GsR3UPPEZ8gV7dQdNJF3Xq0u8... · CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture

CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork

What is difference between copy constructor or shallow copy?

A copy constructor is used to initialize a newly declared Object from an existing Object. This makes a deep copy like assignment.

A shallow copy of an object copies all of the member field values. This works well if the fields are values, but may not be what you want for fields that point to dynamically allocated memory. The pointer will be copied. but the memory it points to will not be copied -- the field in both the original object and the copy will then point to the same dynamically allocated memory.

A deep copy copies all fields, and makes copies of dynamically allocated memory pointed to by the fields. To make a deep copy, you must write a copy constructor and overload the assignment operator, otherwise the copy will point to the original, with disastrous consequences.

I am giving you one example which perform deep copy in this example if you do not override copy constructor then it will give run time error, not perform as what we want so it will be help full for understanding why we have to override copy constructor if compiler provide it by default.

class base {int *a; public: base() {} void allocate() { a = new int(10); } void disp() {cout*aendl; } base(base &b) { a = new int(*(b.a)); }

Prepared By: Irfan Khan (Chief Admin) Page 24

Page 25: CS304 Lecture Wise Questions by Virtualians Social Networkapi.ning.com/files/T-9GsR3UPPEZ8gV7dQdNJF3Xq0u8... · CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture

CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork

~base() { delete a; } };

int _tmain(int argc, _TCHAR* argv[]) { base *b1 = new base; b1->allocate(); base *b2 = new base(*b1); b1->disp(); delete b1; b2->disp(); delete b2; return 0; }

What is an Inline function?

Inline functions is a way used by compilers to improve efficiency of the program, when functions are declared inline normal process of function calling (using stack) is not followed instead function code is added by compiler at all points where these functions have been called. Basic concept behind inline functions is that they are functions in our code but in compiler generated files these functions code is added by compiler at all places where they were called in the code. Normally small size functions that need to be called many times during program execution are declared inline. Inline functions decrease the code execution time because program in their case doesn’t involve function call overhead.

Keyword ‘inline’ is used to request compiler to make a function inline.

However using inline keyword with function doesn’t guarantee that function will definitely in inlined, it depends on the compiler if it finds it can make function inline it does so otherwise it ignores the keyword inline and treat the function as normal function

Prepared By: Irfan Khan (Chief Admin) Page 25

Page 26: CS304 Lecture Wise Questions by Virtualians Social Networkapi.ning.com/files/T-9GsR3UPPEZ8gV7dQdNJF3Xq0u8... · CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture

CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork

What is Navigation?

Navigation is an aspect of a simple association between classes, which refers that whether objects of two classes are related in one way or in two ways. In one-way association, we can navigate in single direction, while in two way association we can navigate in both directions.

Lecture no 9

This Pointer?

This pointer is a constant pointer that stores the memory address of the current object. It is an implicit/hidden parameter to all member functions of a class.

See the use of this pointer in the following example code segment in which value of data member of the current object is setting through this pointer.

class A { int a; public: void set(int a1){ this->a=a1; } };

In order to return current object to the calling function, “return *this” statement is used.

Q:Friend function increase bugs?

As for as your second question is concern, “Friend functions” do not increase bugs, however programmer are required to use friend functions only when there is a need.

Prepared By: Irfan Khan (Chief Admin) Page 26

Page 27: CS304 Lecture Wise Questions by Virtualians Social Networkapi.ning.com/files/T-9GsR3UPPEZ8gV7dQdNJF3Xq0u8... · CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture

CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork

What is class hierarchy?

A set of classes and their interrelationships is called class hierarchy. When a method is invoked on an object it is first looked for in the object’s class, then the superclass of that class and son on up the hierarchy until it is found. Thus a class need only define those methods which are specific to it, and inherit methods from all its superclasses.

Example: Class C is derived from class of B, and B class is derived from class A. Now class C object accessed the method (SetName(char *)), then it first looked in class C, if not found, then looked in class B, if not found, then looked in class A.

What is access specifier?

Access specifier specifies whether that a specific data member is accessible at a particular location in a program. There are three access specifiers in C++. Public specifier tells that this data member can be accessed any where in the program. Protected access specifier tells that this data member can only be accessed in the class, in which it is declared, or in the child class. Private access specifier tells that this data member can only be accessed inside the class, in which it is declared.

Example:

class Student { private: int RollNo; char * Name; protected: int age; public: void display(); };

Now "RollNo" and "Name" can only be accessible in the "Student" class. Similarly "age" can be accessed in the derived class, and "display()" function can be used in any new class, function, or main function.

Prepared By: Irfan Khan (Chief Admin) Page 27

Page 28: CS304 Lecture Wise Questions by Virtualians Social Networkapi.ning.com/files/T-9GsR3UPPEZ8gV7dQdNJF3Xq0u8... · CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture

CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork

What is resolution operator?

:: is called scope resolution operator. Scope resolution operator is used the define data members/functions outside class body or to define static variable. Example:

Student::Student(){cout "Default constructor"; } int Student::noOfStudents=0;

What is override? Override means "dominate", while in OOP override means that child class function override the behaviour of parent class function. The override function must have the same name in both derived and parent class. While accessing base class function through derived class, then the derived class function will execute instead of parent class function.

Example: class Person{ int age; public: void setAge(int _age){ age=_age; } }; class Adult: public Person { int age; public: void setAge(int _age){ if(_age>=18){ age=_age; } cout "Enter the age of an adult person"; }int main(){ Adult obj; obj.setAge(17); // “Adult” class method “setAge()” will be execute system("pause"); }

What is a override function?

Prepared By: Irfan Khan (Chief Admin) Page 28

Page 29: CS304 Lecture Wise Questions by Virtualians Social Networkapi.ning.com/files/T-9GsR3UPPEZ8gV7dQdNJF3Xq0u8... · CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture

CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork

If base class and derived class have member functions with same name and arguments. If you create an object of derived class and write code to access that member function then, the member function in derived class is only invoked, i.e., the member function of derived class overrides the member function of base class. This feature in C++ programming is known as function overriding. Example

Prepared By: Irfan Khan (Chief Admin) Page 29

Page 30: CS304 Lecture Wise Questions by Virtualians Social Networkapi.ning.com/files/T-9GsR3UPPEZ8gV7dQdNJF3Xq0u8... · CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture

CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork

Lecture no 10

What are constant members functions?

Constant member functions are those functions that can not modified the object state. Constant member functions are “read only”. Constant data member function can not change data member. To declare a constant member function, place the const keyword after the closing parenthesis of the argument list. The const keyword is required in both the declaration and the definition. Syntax: class className{ returnValue Function() const; }; Definition: returnValue className:: function() const{ } Example: class Student{ public: int getRollNo() const { return rollNo; } };

Lecture no 11

What is difference between Definition and Declaration ?

Declaration of a variable or function means to tell the compiler about its type, while defition means the exact code.

For example, declaration of function means, to tell the compiler about the return type of function,

Prepared By: Irfan Khan (Chief Admin) Page 30

Page 31: CS304 Lecture Wise Questions by Virtualians Social Networkapi.ning.com/files/T-9GsR3UPPEZ8gV7dQdNJF3Xq0u8... · CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture

CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork

its parameter types etc, while definition of function means the actual code of the function.

Similarly, declaration of a variable means to tell the compiler about its type, while definition means to assign some value to the variable.

Difference between initializing and Assignments? Initialization is assigning value along with creation of variable.

int i;

i=7;

Assignment is assigning value after creation.

Int i;

I=7;

Member Initialize List Member initialization list is used where we cannot modify the state of data members in the member functions of the class including constructor,

Constant Member Functions Make all functions that don’t change the state of the object constant

This will enable constant objects to access more member functions

Static Variables Static variables of a class are such variables which are independent of class objects.

Lifetime of static variable is throughout the program life, if static variables are not explicitly initialized then they are initialized to 0 of appropriate type.

Prepared By: Irfan Khan (Chief Admin) Page 31

Page 32: CS304 Lecture Wise Questions by Virtualians Social Networkapi.ning.com/files/T-9GsR3UPPEZ8gV7dQdNJF3Xq0u8... · CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture

CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork

Lecture no 12

Class Variable:

A variable which is defined inside a class and have same copy for all objects of this class is called class variable that is, static variable in class.

Instance Variable:

A variable which is defined inside a class and have separate copy for each object of this class is called instance variable, that is, normal variable defined inside class (data members).

Lecture no 13

Intrinsic relationship” means, relation between two or more objects which is mandatory or fundamental.

What is primitive data type, primitive variable and structure variable?

The data types “int” , “float”, “char” etc are called primitive data types. Variables of primitive data types are called primitive variable.

The variable of type structure (struct) is called structure variable.

What is main difference b/w Copy Constructor and shallow copy.?

Copy constructor is of two type, default copy constructor and deep copy constructor. The default copy constructor is also called shallow copy.

Lecture no 14

What is bool or boolean when n why we use it? bool” is a data type, when a variable defines with “bool” data type , its value would be either “true” or “false”.

We do not return 0 when a function’s return type is “void”.

Prepared By: Irfan Khan (Chief Admin) Page 32

Page 33: CS304 Lecture Wise Questions by Virtualians Social Networkapi.ning.com/files/T-9GsR3UPPEZ8gV7dQdNJF3Xq0u8... · CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture

CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork

aRollno, Rollno, a_name etc all are user define variables.

Lecture no15

Why const data member of a class need to be initialized at the constructor why not somewhere else?

“const” data members cannot be initialized through constructor; they are initialized through member initialization list.

Further, constructor initializes the state (non constant data members) of an object.

What are binary operators? The operators which take two operands are called binary operators. For example, +, -,* etc

The code examples of binary operators have given in handouts, read handouts thoroughly.

Explain the definition of Operator Overloading? Operator overloading is a technique which allows the basic operators like +, -, = etc to work for user defined type (class/object) as well.

This can be achieved through user defined functions with a keyword “operator” followed by the operator which is going to be overloaded (allow for user defined type).

These functions may be the member functions of the class or non-member functions of the class.

Lecture no 16

Explain the definition of Operator Overloading?

Operator overloading is a technique which allows the basic operators like +, -, = etc to work for user defined type (class/object) as well.

Prepared By: Irfan Khan (Chief Admin) Page 33

Page 34: CS304 Lecture Wise Questions by Virtualians Social Networkapi.ning.com/files/T-9GsR3UPPEZ8gV7dQdNJF3Xq0u8... · CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture

CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork

This can be achieved through user defined functions with a keyword “operator” followed by the operator which is going to be overloaded (allow for user defined type).

These functions may be the member functions of the class or non-member functions of the class.

What are binary operators? The operators which take two operands are called binary operators. For example, +, -,* etc

The code examples of binary operators have given in handouts, read handouts thoroughly.

Lecture no 17

Shallow copy: When an object is created and initialized with an already defined/constructed object, then this copying is done through default copy constructor and such type of copying object is called shallow copy.

In shallow copy the state of the created object is initialized member-wise and as a result both objects pointing to the same memory location. When “const” keyword is used before a variable declaration in the parameter list of a function, it means, the function can use the variable within its body but cannot changes/update its value.

When “const” keyword is used before the return type of a function, it means, the function will return constant value.

When “const” keyword is used after a function name, it means, this member function cannot change/update the object status (that is, cannot change the data members).

Prepared By: Irfan Khan (Chief Admin) Page 34

Page 35: CS304 Lecture Wise Questions by Virtualians Social Networkapi.ning.com/files/T-9GsR3UPPEZ8gV7dQdNJF3Xq0u8... · CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture

CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork

Lecture No 18:

What is a Cascaded expression means?

an expression in which an operator like “=” use more than once, following is an example of cascaded expression.

Obj4 = obj3= obj2 = obj1;

Second, “rhs” is a user define variable name in the given function definition. “+” is a binary operator, when it applies on user define variables (objects), then the right hand side operand must be passed to the function which implement the “+” operator. So here “rhs” has used for right-hand-side operand.

What is Operator overloading? Operator overloading is a technique which allow the basic operators like +, -, = etc to work for user defined type (class/object) as well.

This can be achieved through user defined functions with a keyword “operator” followed by the operator which is going to be overloaded (allow for user defined type).

These functions may be the member functions of the class or non-member functions of the class.

Function overloading: Function overloading means, when there are more than one function with same name and different number or type of arguments, then it is called function overloading.

Complex Number:

It is a number which has two parts “real” and “imaginary” and can be expressed in the form of,

a + bi

Prepared By: Irfan Khan (Chief Admin) Page 35

Page 36: CS304 Lecture Wise Questions by Virtualians Social Networkapi.ning.com/files/T-9GsR3UPPEZ8gV7dQdNJF3Xq0u8... · CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture

CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork

Lecture No 19:

What is difference Between Shallow Copy and Deep Copy?

Shallow copy: When an object is created and initialized with an already defined/constructed object, then this copying is done through default copy constructor and such type of copying object is called shallow copy.

In shallow copy the state of the created object is initialized member-wise and as a result both objects pointing to the same memory location. Deep copy: In the deep copy new memory assign to the new created object instead of pointing it (member-wise copying) to pre defined object.

Lecture No 20

What is Self assignment ?

Self assignment means, assigning a string to itself. It may create problem, because as the source and destination variables are the same and we release (delete memory) the destination variable before assignment.

Copy constructor? A constructor which is used to copy one object to another is called copy constructor. There are two type of copy constructors, Default copy constructor which is also called shallow copy and deep copy constructor.

Prepared By: Irfan Khan (Chief Admin) Page 36

Page 37: CS304 Lecture Wise Questions by Virtualians Social Networkapi.ning.com/files/T-9GsR3UPPEZ8gV7dQdNJF3Xq0u8... · CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture

CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork

Lecture No 21:

Behavior of ++ and -- for pre-defined types: §Pre-increment ++:►Pre-increment operator ++ increments the current value and then returns it’s reference§Pre-decrement --:►Works exactly like Pre-increment ++►Example: int x = 2, y = 2;

++++y;

cout y;

++y = x;

cout y;

►Output: 4

2

Lecture No 22:

Inheritance in Classes If a class B inherits from class A, then B contains all the characteristics (information structure and behavior) of class A

The parent class is called base class and the child class is called derived class

Besides inherited characteristics, derived class may have its own unique characteristics

Prepared By: Irfan Khan (Chief Admin) Page 37

Page 38: CS304 Lecture Wise Questions by Virtualians Social Networkapi.ning.com/files/T-9GsR3UPPEZ8gV7dQdNJF3Xq0u8... · CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork Lecture

CS304 LeCture WiSe QueStionS by VirtuaLianS SoCiaL netWork

Types of Inheritance in C++ ►There are three types of inheritance in C++

Public

Private

Protected

What is "IS A” Relationship? IS A relationship is modeled with the help of public inheritance

Syntax

class ChildClass

: public BaseClass{

...

};

Base Class Initializer ►C++ has provided a mechanism to explicitly call a constructor of base class from derived class

►The syntax is similar to member initialize and is referred as base-class initialization

Prepared By: Irfan Khan (Chief Admin) Page 38