Write any four differences between compile time and run time polymorphism.

1 Answer

Answer :

Sr. No.
Compile-time Polymorphism
Run-time Polymorphism
1 Compile time polymorphism means that an object is bound to its function call at compile time.
Run time polymorphism means that selection of appropriate function is done at run time.
2 Functions to be called are know well before.
Function to be called is unknown until appropriate selection is made.
3 This does not require use of pointer to object.
This requires use of pointers to object.
4 Function calls are faster.
Function call execution is slower. 
5 It is also called as early binding.
It is also called as late binding. 
6 It also referred as static binding
It also referred as dynamic binding.
7 E.g. overloaded function call.
E.g. virtual function.

Related questions

Description : Compare run-time and compile-time polymorphism.

Last Answer : Compare run-time and compile-time polymorphism.

Description : How to achieve compile time polymorphism explain in detail.

Last Answer : The process of linking of function call to function definition at compile time is called as Compile Time Polymorphism. It can be through Function and operator overloading. Function overloading: The process of defining the ... \n Concatenated String is:"; str1.display(); getch(); }  

Description : What is polymorphism? Enlist different types of polymorphism. What are the differences between them?

Last Answer : Polymorphism: It is a feature of object oriented programming which allows a programmer to have a more than one function having same name but different /same parameters but performs different/ ... Compile Time polymorphism o Virtual Function Difference between Types of Polymorphism:

Description : Polymorphism is implemented using function overloading. Justify the statement.

Last Answer : Polymorphism is a mechanism that allows a developer to have more than one function with same name but different signature. In function overloading, one can make use of more than one function with different signature as well. Hence ... main()  { int a[10],i,isum; float b[5],fsum; clrscr(); cout

Description : Define polymorphism. Enlist its types.

Last Answer : Definition: Polymorphism means ability to take more than one form that means a program can have more than one function with same name but different behavior. Types of polymorphism: 1) Compile time polymorphism 2) Runtime polymorphism 

Description : Define the following terms: (i) Data abstraction (ii) Class (iii) Dynamic binding (iv) Polymorphism

Last Answer : (i) Data abstraction: Abstraction refers to the act of representing essential features without including the background details or explanation. Data abstraction is the process of defining a data type, often ... more than one form at different instances depending on the type or number of arguments. 

Description : With suitable example, describe use of virtual function in polymorphism.

Last Answer : In order to achieve polymorphism, objects belonging to different classes should be able to respond to the same message at different instances which initiates the use of single pointer variable to refer to objects of ... void accept() { coutroll; coutname; } virtual void display() { cout

Description : Define what is the difference between compile-time polymorphism and run-time polymorphism?

Last Answer : Compile time Polymorphism Compile time Polymorphism also known as method overloading. Method overloading means having two or more methods with the same name but with different signatures. Run time ... or more methods with the same name, same signature but with a different implementation.

Description : Differentiate between run time and compile time polymorphism.

Last Answer : Sr. No. Compile time polymorphism Runtime polymorphism 1 In this polymorphism, an object is bound to its function call at compile time. In this polymorphism, ... is implemented with operator overloading or function overloading It is implemented with virtual function.

Description : Give four differences between object oriented programming and procedure oriented programming.

Last Answer : Give four differences between object oriented programming and procedure oriented programming.

Description : Write any four characteristics of constructor.

Last Answer : The constructor functions have some special characteristics. They should be declared in the public section. They are invoked automatically when the objects are created. They do not have return types ... They make 'implicit calls' to the operators new and delete when memory allocation is required.

Description : Why friend function is required? Give four characteristics of friend function.

Last Answer : Friend function: Private members of a class cannot be accessed from outside the class. A non-member function cannot have an access to the private data of a class. Sometimes, two classes may need to ... part of a class without affecting its meaning. 6. Usually it has the objects as the arguments.

Description : State any four object oriented programming language.

Last Answer : Object oriented programming language: C++ Smalltalk Object pascal java Simula Ada Turbo pascal Eiffel C# Python

Description : Explain any four concept of OOP.

Last Answer : Basic Concepts of Object Oriented Programming:  1. Objects Objects are the basic run time entities in an object-oriented system. They may represent a person, a place, a bank ... objects that communicate with each other. Objects communicate with one another by sending and receiving information.

Description : State any four rules for operator overloading.

Last Answer : Rules for operator overloading: 1. Only existing operators can be overloaded. New operators cannot be created. 2. The overloaded operator must have at least one operand that is of user defined type. 3. ... * and / must explicitly return a value. They must not attempt to change their own arguments. 

Description : State any four characteristics of friend function.

Last Answer : Characteristics of friend function: 1. It is not in the scope of the class to which it has been declared as friend. 2. As it is not in the scope of the class, it cannot be called using the ... public or the private part of a class without affecting its meaning. 6. It has the objects as arguments.

Description : State any four types of constructor.

Last Answer : Types of constructor: Default constructor Parameterized Constructor Constructor with Default Argument Copy Constructor Multiple/overloaded constructor

Description : State any four applications of OPP.

Last Answer : Applications of OOP: Real time systems Simulation and modeling Object-oriented databases Hypertext, hypermedia and expert Ext AI and expert systems Neural networks and parallel programming Decision support and office automation systems CIM/CAM/CAD systems

Description : Write a program which concate and reverse string by using pointer to string.

Last Answer : #include #include void main()  { char str1[20], str2[20], rev[20],*p1,*p2; int cnt=0; clrscr(); coutstr2;  p1=&str1[0];  p2=&str2[0]; while(*p1!='\0')  { p1++;  } while(*p2!='\0')  { *p1=*p2; p1++; p2++;  }  *p1='\0'; cout

Description : Write a program which perform arithmetic operation using pointer.

Last Answer : #include<iostream.h> #include<conio.h> void main() { int num[5]={56,75,22,18,90}; int ptr; int i; cout<< array elements are:: ; for(i=0;i<5;i++) ptr=num; cout<< ... 3; cout<< value of ptr+=3:: <<*ptr; cout<< \n ; getch(); }

Description : Write a program which implement the concept of overloaded constructor.

Last Answer : #include #include class integer { int m,n; public: integer() { m=0; n=0; } //default constructor 1 integer(int a, int b) { m=a; n=b; } //Parameterized constructor 2 integer(integer &i) { m=i.m; n=i.n; } //copy constructor 3 }; void display() { cout

Description : Write down characteristics of object oriented programming.

Last Answer : Characteristics of object oriented programming are: Emphasis is on data rather than procedure. Programs are divided into objects. Data structures are designed such that they characterize the ... can be easily added whenever necessary. Follows bottom-up approach in program designing. 

Description : What is pure virtual functions? Write down the rules used for pure virtual function.

Last Answer : A pure virtual function is a function which is declared in a base class and which does not have definition relative to the base class. In such cases, the compiler requires each derived class to either ... A class containing pure virtual functions cannot be used to declare any objects of its own.  

Description : Write a program to find whether the string is palindrome or not.

Last Answer : #include #include #include void main() { char str1[10],str2[10]; int c; clrscr(); coutstr1; strcpy(str2,str1); strrev(str2); cout

Description : Write a program for multiple inheritance. 

Last Answer : #include #include class base1 { public: void show1() { cout

Description : Write a program to show object as function argument. 

Last Answer : #include<iostream.h> #include<conio.h> #include<string.h> class objarg  { char str[10]; public: void get() { cout<<"\n Enter a Message"; cin>>str; } void ... clrscr(); o1.get(); o2.copy(o1); o2.display(); getch();  }

Description : Write a program to declare class student having data members name and percentage. Write constructor to initialize these data members. Accept and display this data for one object.

Last Answer : #include<iostream.h> #include<conio.h> #include<string.h> class student { char name[20]; float per; public: student(char n[],float p) { strcpy(name,n); per=p; } ... { student S("Sachin",78.00); clrscr(); S.putdata(); getch(); }

Description : Write a program to copy content of one string to another string using pointer to string.

Last Answer : #include<iostream.h> #include<conio.h> void main() { char str1[10],str2[10],*p1,*p2; clrscr(); cout<<"\n Enter a String"; cin>>str1; p1=&str1[0]; p2= ... } *p2='\0'; cout<<"Copied String is "<<str2; getch(); }

Description : Write a program for overloading of ++unary operator for inch to feet conversion. 12 inch = 1 feet.

Last Answer : #include #include class abc { int i,f; public: abc(int f1,int i1) { f=f1; i=i1; } void operator ++() {  while(i>11)  {  f++;  i=i-12;  }  cout

Description : Write a program to swap two integer values by using call by reference.

Last Answer : #include #include void swap(int *a,int *b) { int c; c=*a; *a=*b; *b=c; } void main() { int a,b; couta; coutb; cout

Description : Write a program to implement single inheritance. Declare base class employee with Emp_No. and Emp_Name. Declare derived class fitness with height and weight. Accept and display data for one employee.

Last Answer : #include<iostream.h> #include<conio.h> class employee { protected: int emp_no; char emp_name[10]; public: void gete() { cout<< enter employee details ; cin>>emp_no; cin>> ... f.gete(); f.pute(); f.getft(); f.putft(); getch(); }

Description : Write a program to declare class having data member as hrs, mins, secs. Write constructor to assign values and destructor to destroy values. Accept & display data for one object.

Last Answer : #include<iostream.h> #include<conio.h> class time { private: int hrs, mins,sec; public: time(int h,int m,int s) { hrs=h; mins=m; sec=s; } ~time() { cout<< hours ... } }; void main() { time t(2,43,56); t.display(); getch(); }

Description : Write a program to find length of a string using pointer to string.

Last Answer : #include<iostream.h> #include<conio.h> void main() { char str1[10],*ptr; int len=0; cout<<"enter string:"; cin>>str1; ptr=&str1[0]; while(*ptr!='\0 ... +; } cout<<"\nThe Length of a string is"<<len; getch(); }

Description : Write a program to implement the concept of virtual base class for following figure. Accept and display information of one employee with his name, code, basic pay, experience and gross salary with the object of employee class.

Last Answer : #include<iostream.h> #include<conio.h> class Master  {  char name[10],code[3];  public:  void acceptM() { cout<<"\nEnter name and code "; cin>>name>>code; ... .displayM(); e.displayA(); e.displayD(); e.displayE(); getch();  }

Description : Write a program to declare a class 'staff' having data members as name and department. Accept this data for 10 staffs and display names of staff that are in 'CO' department.

Last Answer : #include<iostream.h> #include<conio.h> #include<string.h> class staff {  char name[10], dept[10];  public:  void accept() { cout<<"Enter Name and Department:\t"; cin>> ... i=0;i<=10;i++) { s[i].display(); } getch(); }

Description : Write a program to calculate area of circle and area of rectangle using function overloading. 

Last Answer : #include<iostream.h> #include<conio.h> float area(float a) { return (3.14*a*a); } int area(int p,int q) { return(p*q); } void main() { clrscr(); cout< ... ;<<area(6); cout<<"Area of Rectangle:"<<area(5,6); getch(); }

Description : Write a program to search a number from an array using pointer to array.

Last Answer : #include<iostream.h> #include<conio.h> void main() { int a[5],i,*a1,no,flag=1; clrscr(); a1=&a[0]; cout<<"\nEnter array elements :"<<endl; for(i=0;i<5 ... =0) { cout<<"\n\t Number is not present.... "; } getch(); }

Description : Write any two advantages of inheritance.

Last Answer : Advantages of inheritance: 1) Use of inheritance in a program gives reusability of code. 2) Inheritance avoids duplication of code in program. 3) Inheritance reduces length of code. 4) Inheritance reduces time to compile the lengthy code by reusing it. 

Description : Write a program using concept of pointers to string for performing following operations: (i) String concatenation (ii) String comparisons

Last Answer : (i) Program to implement String Concatenation: #include #include void main() { char s1[50],s2[30],*p,*q; clrscr(); couts1>>s2; p=s1; q=s2; while(*p!=NULL) { p++; } while(*q!=NULL) { *p=*q; p++; q++; } *p='\0'; cout

Description : Write a program to demonstrate the use of pure virtual function.

Last Answer : Consider the following example where parent class provides an interface to the base class to implement a function called getArea() as pure virtual function: #include // Base class class Shape { protected: int ... ; Rect.setWidth(5); Rect.setHeight(7); // Print the area of the object. cout

Description : Write a program to overload ‘+’ operator to concatenate two strings.

Last Answer : #include #include #include class string1 { char str[20]; public: void getdata() { coutstr; } void display() { cout

Description : Write use of ‘This’ pointer.

Last Answer : this pointer is used to represent an object that invokes a member function. It points to the object for which the function is called. It is also used to access members of object inside function definition of called function

Description : Write a program in C++ to accept a string from a user and display its reverse using pointer.

Last Answer : #include<iostream.h> #include<conio.h> #include<string.h> void main() { char str[20],*ptr; int l; clrscr(); cout<<"\n Enter a string : "; cin>>str; l=strlen(str); ... (l!=0) { ptr--; cout<<*ptr; l--; } getch(); }

Description : Write a program in C++ to implement single inheritance from following figure:

Last Answer : #include<iostream.h> #include<conio.h> class product { protected: int prodid; char prodname[20]; }; class edible:public product { char flavour[20]; public: void accept() { cout<< ... for(i=0;i<5;i++) { e[i].display(); } getch(); }

Description : Write a program in C++ to declare a class „Journal‟ having data members as journal_nm, price, ISSN_No. Accept this data for two objects and display the name of the journal having greater price.

Last Answer : #include<iostream.h> #include<conio.h> class Journal { char journal_nm[20]; int ISSN_No; float price; public: void accept(); void display(Journal); }; void Journal::accept() { ... clrscr(); j1.accept(); j2.accept(); j1.display(j2); getch(); }

Description : Write a program in C++ to overload a „volume‟ function to calculate volume of cube and rectangular box. 

Last Answer : #include<iostream.h> #include<conio.h> void volume(float); void volume(float, float, float); void main() { float a, length, width, height; clrscr(); cout<<"\n ... width*height; cout<<"\n Volume of a rectangular box is:"<<v; }

Description : Write a program in C++ to implement following inheritance. Assume suitable data.

Last Answer : #include<iostream.h> #include<conio.h> class employee { int empid; char empname[20]; public: void accept() { cout<<"\n enter empid, empname:"<<endl; cin>>empid>> ... m.acc1(); m.dis1(); w.acc2(); w.dis2(); getch(); }

Description : Write a C++ program to overload = = operator to check equality of two strings.

Last Answer : #include<iostream.h> #include<conio.h> #include<string.h> class string { char str1[20]; public: void get() { cout<<"Enter string:"; cin>>str1; } void operator = =( ... ; string s,s1; s.get(); s1.get(); s==s1; getch(); }

Description : Write a program in C++ to declare a class measure having data members as add 1, add 2, add 3. Initialize the values of two data members using constructor and display their addition using function.

Last Answer : #include<iostream.h> #include<conio.h> class measure { public: int add1,add2,add3; measure(int a,int b) { add1=a; add2=b; } void cal() { add3=add1+add2; } void display() ... ;>a>>b; measure m1(a, b); m1.cal(); m1.display(); getch(); }

Description : Write a program in C++ to search an element from an array using pointer.

Last Answer : #include<iostream.h> #include<conio.h> void main() { int a[10], n, i,*p, flag=0, x; clrscr(); cout<<"Enter no. of array elements \n"; cin>>n; cout<< ... } if(flag==0) cout<<x<<"is not found \n"; getch(); }