Get the most accurate TN Board Solutions for Class 11 Computer Science Chapter 15 Polymorphism here. Updated for the 2026-27 academic session, these solutions are based on the latest TN Board textbooks for Class 11 Computer Science. Our expert-created answers for Class 11 Computer Science are available for free download in PDF format.
Detailed Chapter 15 Polymorphism TN Board Solutions for Class 11 Computer Science
For Class 11 students, solving TN Board textbook questions is the most effective way to build a strong conceptual foundation. Our Class 11 Computer Science solutions follow a detailed, step-by-step approach to ensure you understand the logic behind every answer. Practicing these Chapter 15 Polymorphism solutions will improve your exam performance.
Class 11 Computer Science Chapter 15 Polymorphism TN Board Solutions PDF
Part I
Choose The Correct Answer:
Question 1. Which of the following refers to a function having more than one distinct meaning?
(a) Function Overloading
(b) Member overloading
(c) Operator overloading
(d) Operations overloading
Answer: (a) Function Overloading
In simple words: Function overloading is when a single function name is used for different functions that do slightly different things, usually based on the types or number of inputs they receive.
π― Exam Tip: Remember that function overloading is a key aspect of polymorphism in C++, allowing the same function name to be used for multiple tasks.
Question 2. Which of the following reduces the number of comparisons in a program?
(a) Operator overloading
(b) Operations overloading
(c) Function Overloading
(d) Member overloading
Answer: (c) Function Overloading
In simple words: Using function overloading can make your code shorter and reduce the number of times the program has to check different conditions. This is because the compiler picks the right function based on its inputs.
π― Exam Tip: Function overloading is often preferred because it improves code readability and reduces the need for multiple function names performing similar operations.
Question 3. void dispchar(char ch='$',int size=10)
{
for(int i=1;i<=size;i++)
cout<<ch;
}
How will you invoke the function dispchar() the following input?
To print $ for 10 times
(a) dispchar();
(b) dispchar(ch,size);
(c) dispchar($,10);
(d) dispcharC$', 10 times);
Answer: (a) dispchar();
In simple words: To call the `dispchar` function and print '$' ten times, you just need to use `dispchar();` because the function already has default values set for the character and the number of times it should print.
π― Exam Tip: When a function has default arguments, you can call it without passing any arguments, and it will use those default values. This makes the function call simpler.
Question 4. Which of the following is not true with respect to function overloading?
(a) The overloaded functions must differ in their signature.
(b) The return type is also considered for overloading a function.
(c) The default arguments of overloaded functions are not considered for Overloading.
(d) Destructor function cannot be overloaded.
Answer: (b) The return type is also considered for overloading a function.
In simple words: When you overload functions, only the types and number of inputs matter, not what kind of value the function gives back (its return type). So, two functions with the same inputs but different return types cannot be overloaded.
π― Exam Tip: Understand that function signature includes the function name and its parameter list (types, order, and number of parameters), but not the return type. This is crucial for correctly overloading functions.
Question 5. Which of the following is an invalid prototype for function overloading?
(a) void fun (int x);
void fun (char ch);
(b) void fun (int x);
void fun (int y);
(c) void fun (double d);
void fun (char ch);
(d) void fun (double d);
void fun (int y);
Answer: (b) void fun (int x);
void fun (int y);
In simple words: You cannot overload two functions if they only differ by the names of their input variables, like `int x` and `int y`. They must differ by the type or number of inputs, not just their names.
π― Exam Tip: For valid function overloading, the functions must have different parameter lists. This means a different number of parameters or different data types for parameters, or a different order of parameter types.
Question 6. Which of the following function(s) combination cannot be considered as overloaded function(s) in the given snippet?
void print(char A,int B); // F1
void printprint(int A, float B); // F2
void Print(int P=10); // F3
void print(); // F4
(a) F1,F2,F3,F4
(b) F1,F2,F3
(c) F1,F2,F4
(d) F1,F3,F4
Answer: (b) F1,F2,F3
In simple words: Functions F1, F2, and F3 cannot be overloaded with each other because they either have different names (like `printprint` vs `print`) or their signatures are not distinct enough for overloading by just changing case (like `Print` vs `print`) or the presence of default arguments does not create a unique signature.
π― Exam Tip: Function overloading requires the function names to be identical and their parameter lists (types, number, and order of arguments) to be unique. Pay attention to case sensitivity in function names.
Question 7. Which of the fallowing operator is by default overloaded by the compiler?
(a) *
(b) +
(c) +=
(d) ==
Answer: (c) +=
In simple words: The `+=` operator is often overloaded by the compiler for built-in types, meaning it already knows how to add and assign values for common data types.
π― Exam Tip: Many assignment operators like `+=`, `-=`, `*=`, `/=`, and `%=` are automatically overloaded by the compiler for fundamental data types. Understanding this saves you from manually overloading them.
Based on the following program answer the questions (8) to (10)
#include<iostream>
using namespace std;
class Point
{
private:,
int x, y;
public:
Point(int x1,int y1)
{
x=x1;
y=y1;
}
void operator+(Point &pt3);
void show()
{
cout << "x = " << x << ", y = "<<y;
}
};
void Point::operator+(Point &pt3)
{
x += pt3.x;
y += pt3.y;
}
int main()
{
Point pt1(3,2),pt2(5,4);
pt1+pt2;
pt1.show();
return 0;
}
Question 8. Which of the following operator is overloaded?
(a) +
(b) operator
(c) ::
(d) =
Answer: (a) +
In simple words: In the given code, the plus `+` operator has been given a special job to add two `Point` objects together. This means it's been overloaded.
π― Exam Tip: Look for the keyword `operator` followed by a symbol within a class definition. This clearly indicates an overloaded operator.
Question 9. Which of the following statement invoke operator overloading?
(a) pt1+pt2;
(b) Point pt1(3,2),pt2(5,4);
(c) pt1.show();
(d) return 0;
Answer: (a) pt1+pt2;
In simple words: The line `pt1+pt2;` calls the special `operator+` function that was defined for the `Point` class. This is how the overloaded plus operator is used.
π― Exam Tip: Operator overloading is invoked when you use the overloaded operator with objects of the class for which it is defined. The syntax `object1 operator_symbol object2` is the typical way it's used.
Question 10. What is the output for the above program?
(a) x=8, y=6
(b) x=14, y=14
(c) x=8, y=6
(d) x=5, y=9
Answer: (a) x=8, y=6
In simple words: The program adds the x and y values of `pt1` (3, 2) and `pt2` (5, 4). So, x becomes 3+5=8 and y becomes 2+4=6. The `pt1.show()` then displays these new values.
π― Exam Tip: Trace the values of the objects through each step of the program, especially after operator calls, to predict the final output accurately.
Part - II
Very Short Answers
Question 1. What is function overloading?
Answer: Function overloading means that a function can work with different types or numbers of inputs. It allows two or more functions in the same part of the program to share the same name, but they must have different sets of parameters. This ability of a function to process data in more than one form is a key feature of polymorphism.
In simple words: Function overloading is when you have many functions with the same name, but they take different kinds of inputs. The computer knows which one to use based on what you give it.
π― Exam Tip: Define function overloading by emphasizing the same function name but different parameter lists. This is the core concept examiners look for.
Question 2. List the operators that cannot be overloaded.
Answer: The following operators cannot be overloaded in C++:
- Scope resolution operator \( :: \)
- Sizeof operator (`sizeof`)
- Member selector operator (`.`)
- Member pointer selector operator (`.*`)
- Ternary operator \( ?: \)
In simple words: Some special computer symbols, like `::` (for scope), `sizeof` (for size), `.` (for members), `.*` (for pointer members), and `?:` (for choices), cannot be given new jobs. They always do the same thing.
π― Exam Tip: Memorize this list of non-overloadable operators. Knowing these exceptions can prevent common errors in C++ programming.
Question 3. class add
{
int x;
public:
add(int);
};
Write an outline definition for the constructor.
Answer:
OUTLINE CONSTRUCTOR DEFINITIONadd :: add(int a)
{
x = a;
cout<<"\nParameterized constructor";
}
This definition initializes the member variable `x` with the value passed to the constructor. It also prints a message to show that the parameterized constructor has been called.
In simple words: The outline constructor code shows how to set up the `add` class when you create a new object, by giving `x` a starting number and printing a message.
π― Exam Tip: Remember that constructors are special member functions used for initializing objects. An outline definition typically includes the class name, scope resolution operator, constructor name, parameters, and the body of the function.
Question 4. Does the return type of function help in overloading a function?
Answer: No, the return type of overloaded functions is not considered when overloading a function. For functions to be overloaded, they must have the same name but differ in their parameter list (number, type, or order of parameters), not just their return type. A function's signature includes its name and parameter list, but not its return type.
In simple words: No, what a function gives back (its return type) does not help when overloading it. Only the types and number of inputs it takes are important.
π― Exam Tip: Clearly state that only the function signature (name + parameter list) determines if a function can be overloaded, not the return type. This is a common point of confusion.
Question 5. What is the use of overloading a function?
Answer: Function overloading offers several benefits:
- It is a way to implement polymorphism, which means using a single interface for different types of data.
- It reduces the number of comparisons in a program, allowing for faster execution.
- It helps programmers by reducing the need for many different function names for similar actions.
- Overall, it reduces program complexity by allowing a single function name to handle various input scenarios gracefully.
In simple words: Overloading functions makes code cleaner by letting you use one name for similar jobs that take different inputs. It also helps the program run faster and makes it simpler for the programmer.
π― Exam Tip: Focus on the advantages like increased code readability, reduced complexity, and the implementation of polymorphism when explaining the use of function overloading.
Part - III
Short Answers
Question 1. What are the rules for function overloading?
Answer: Here are the main rules for function overloading:
- The overloaded functions must have different numbers of arguments or different data types for their arguments.
- The return type of overloaded functions is not considered when deciding if functions can be overloaded.
- The default arguments of overloaded functions are not counted as part of the parameter list for checking overloading rules. Instead, the actual parameters provided during the function call determine which overloaded function is selected.
In simple words: For functions to be overloaded, they must have the same name but take different kinds of inputs. This means either the number of inputs is different, or the types of inputs are different. What the function gives back (its return type) does not matter for overloading.
π― Exam Tip: Emphasize that uniqueness in the parameter list is the core requirement for function overloading, and explicitly state that the return type is irrelevant for this purpose.
Question 2. How does a compiler decide as to which function should be invoked when there are many functions? Give an example.
Answer: The compiler decides which function to use based on the function's "signature." A function's signature includes its name and the number and types of its parameters. When an overloaded function is called, the compiler looks at the types of arguments provided in the call. It then compares these argument types with the parameter types defined in all the overloaded functions. This process, called "overload resolution," helps the compiler pick the most suitable definition to use.
Example:float area (float radius); // Function to calculate area of a circle
float area (float half, float base, float height); // Function for area of a triangle
float area (float length, float breadth); // Function for area of a rectangle
According to the input passed, the respective function is called.
For example:x= area(5); // calls area() with one input (float radius) - for circle
x= area(5,6); // calls area() with two inputs (float length, float breadth) - for rectangle
x= area(0.5,5,6);// calls area() with three inputs (float half, float base, float height) - for triangle
In simple words: The computer checks the "signature" of the function you call, which means looking at its name and what kind and how many inputs you give it. Then it finds the matching function definition and runs that one. For example, if you call `area` with one number, it might calculate a circle's area, but with two numbers, it might find a rectangle's area.
π― Exam Tip: Use a clear example with different parameter lists to illustrate how the compiler performs overload resolution, matching the function call's arguments to the correct function definition.
Question 3. What is operator overloading? Give some example of operators which can be overloaded.
Answer: Operator overloading is a feature in C++ that allows you to give additional or special meaning to standard C++ operators when used with user-defined data types (like objects of a class). This means an operator can behave differently depending on the type of data it's used with, while still keeping its original meaning for basic data types. It enhances the readability and expressiveness of code.
Example:
The following operators can be overloaded: \( + \), \( ++ \), \( - \), \( -- \), \( += \), \( -= \), \( * \), \( < \), \( > \), etc.
In simple words: Operator overloading is when you teach a normal computer symbol, like plus `+` or minus `-`, to do a new job when used with your own custom data types, like objects. For example, you can make `+` add two objects in a special way.
π― Exam Tip: Explain operator overloading as giving "additional functionality" to existing operators for "user-defined data types." Provide a few common examples to illustrate the concept clearly.
Question 4. Discuss the benefit of constructor overloading.
Answer: Constructor overloading allows a class to have multiple constructors, each with a different parameter list (signature). This offers great flexibility in creating objects of a class in various ways. For instance, you could have one constructor that sets up an object with default values, another that takes some initial values, and a third that copies values from an existing object. This means:
- Memory is allocated for the objects when they are created.
- Objects can be initialized in different ways, making the class more adaptable to various programming needs.
In simple words: Constructor overloading means you can set up new objects from a class in many ways. You can create an object with no starting values, or give it some specific starting values, or even copy values from another object. This makes creating objects very flexible.
π― Exam Tip: Highlight the "flexibility in creating multiple types of objects" and the "different initialization methods" as the primary benefits of constructor overloading.
Question 5. class sale
{
int cost, discount;
public:
sale(sale &);
};
Write a non-inline definition for the constructor specified;
Answer:
Non-inline definition for constructor:sale :: sale(sale &s)
{
cost = s.cost;
discount = s.discount;
}
This is a copy constructor that initializes a new `sale` object by copying the `cost` and `discount` values from an existing `sale` object (`s`). This is useful for creating a duplicate of an object.
In simple words: This code shows how to make a new `sale` object that is an exact copy of another `sale` object. It takes the cost and discount from the old object and puts them into the new one.
π― Exam Tip: When writing a copy constructor, ensure that all member variables are correctly copied from the source object. This definition is typically `ClassName::ClassName(const ClassName& otherObject)`. The `const` is usually added to prevent accidental modification of the source object.
Explain In Detail
Question 1. What are the rules for operator overloading?
Answer: When you implement operator overloading, you must follow these rules:
- The original precedence and associativity of an operator cannot be changed. For example, multiplication will always happen before addition.
- You cannot create new operators; you can only overload existing operators.
- You cannot redefine the fundamental meaning or procedure of an operator for basic data types. For instance, you cannot change how `int` numbers are added; you can only add additional functions for user-defined types.
- Overloaded operators cannot have default arguments.
- When binary operators (those that work with two operands) are overloaded, the operand on the left side must be an object of the relevant class for the operator to be a member function.
In simple words: When you make an operator do a new job, you cannot change its basic rules, like which calculations happen first. You also cannot make up new symbols for operations; you can only teach old symbols new tricks for your own data types. Plus, you cannot change how numbers normally add or subtract.
π― Exam Tip: Focus on rules like "no new operators," "precedence/associativity cannot change," and "cannot redefine basic types' behavior" as these are critical constraints of operator overloading.
Question 2. Answer the question (i) to (v) after going through the following class.
classBook
{
int BookCode ;
char Bookname[20];
float fees;
public:
Book() //Function 1
{
fees = 1000;
BookCode=1;
strcpy (Bookname,"C++");
}
void display(float C) //Function 2
{
cout<< BookCode << ":" << Boo kname<<":"<<fees<<endl;
}
~Book() //Function 3
{
cout<<"End of Book
Object"<<endl;
}
Book (int BC,char S[ ],float F); //Function 4
};
(i) In the above program, what are Function 1 and Function 4 combined together referred to?
(ii) Which concept is illustrated by Function3? When is this function called/invoked?
(iii) What is the use of Function3?
(iv) Write the statements in main to invoke function1 and function2
(v) Write the definition for Function4
Answer:
(i) Function 1 is a default constructor and Function 4 is a parameterized constructor. Combined, they show the concept of **Constructor Overloading**. This allows objects to be created and initialized in different ways.
(ii) Function 3, `~Book()`, illustrates the concept of a **Destructor**. This function is called automatically when an object goes out of scope, meaning when it is no longer needed.
(iii) The use of Function 3 (`~Book()`) is to **remove the memory space** of the object that was set aside during its creation. It helps in cleaning up resources.
(iv) To invoke Function 1 and Function 2 in `main()`:a) Book b; // object b automatically calls the constructor function Book() (Function 1)
b) b.display(4.5); // Invokes the display function by passing 4.5. (Function 2)
(v) Definition of Function 4:Book (int BC,char S[ ],float F)
{
fees=F;
BookCode=BC;
strcpy (Bookname,S);
}
This parameterized constructor initializes a `Book` object with a specific book code, name, and fees.
In simple words: (i) Functions 1 and 4 are different ways to start an object, which is called Constructor Overloading. (ii) Function 3 is a Destructor, which cleans up an object when it's no longer needed, and it runs on its own. (iii) It helps free up memory. (iv) To use them, you would create a `Book` object, and then call its `display` method with a number. (v) Function 4 helps make a new book object by giving it a code, name, and fees.
π― Exam Tip: When analyzing class structures, identify constructors (default and parameterized), destructors, and member functions. Understand their roles and how they are invoked. Pay attention to how different constructors contribute to polymorphism through overloading.
Question 3. Write the output of the following program.
#include<iostream>
using namespace std;
class Seminar
{
int Time;
public:
Seminar()
{
Time=30;cout<<"Seminar starts now"<<endl;
}
void Lecture()
{
cout<<"Lectures in the seminar on"<<endl;
}
Seminar(int Duration)
{
Time=Duration;cout <<"Welcome to Seminar "<<endl;
}
Seminar(Seminar &D)
{
Time=D.Time;cout<<"Recap of Previous Seminar Content "<<endl;
}
~Semina r()
{
cout<<"Vote of thanks"<<endl;
}
};
int main()
{
Seminar s1,s2(2),s3(s2);
s1.LectureQ;
return 0;
}
Answer: The program demonstrates constructor overloading and destructor calls. The output shows messages from the default constructor, parameterized constructor, copy constructor, a member function call, and then multiple destructor calls as objects go out of scope.
Seminar starts now Welcome to Seminar Recap of Previous Seminar Content Lectures in the seminar on Vote of thanks Vote of thanks Vote of thanks
In simple words: The program will print messages from different parts of the `Seminar` class. First, it announces the seminar starting, then welcomes you, recaps old content, talks about lectures, and finally, thanks you three times as the program finishes and cleans up.
π― Exam Tip: Carefully trace the object creation and destruction order in `main()`. Each constructor call and destructor call will generate output. Pay attention to which constructor is called (default, parameterized, or copy) based on the arguments provided when objects are declared.
Question 4. Debug the following program.
#include
using namespace std;
class String
{
public:
char str[20];
public:
void accept_string()
{
cout<<"\n Enter String : ";
cin>>str;
}
void display_string()
{
cout<
String operator *(String x) //Concatenating String
{
String s;
strcat(str,str);
strcpy(s.str,str);
gotos;
}
}
int main()
{
String str1, str2, str3;
str1.accept_string();
str2.accept_string();
Cout<<"\n\n First String is : ";
str1.display_string();
cout<<"\n\n Second String is : ";
str2.display_string();
str3=str1+str2;
cout<<"\n\n Concatenated String is :";
str3.display_string();
return 0;
}
Answer: The original program has several errors. The `charstr[20];` line should be `char str[20];` (space missing). The `gotos;` line is incorrect and seems like a typo, perhaps intended as a return statement or part of a different logic flow. The `String operator *(String x)` uses `*` for concatenation, which is unusual; typically, `+` is used for string concatenation in C++. The `strcat(str,str);` and `strcpy(s.str,str);` logic for `operator*` is flawed for string concatenation. The `Cout` should be `cout` (lowercase 'c'). The class definition is missing a semicolon at the end.
The correct program should define the `operator+` for string concatenation properly. This involves creating a new String object, concatenating the two strings into it, and then returning the new object. In the `main` function, `Cout` needs to be `cout`, and the `str3=str1+str2;` line needs the `operator+` to be correctly defined.
Here is the corrected program:
Correct Program :
#include
#include
using namespace std;
class String
{
public:
char str[20];
void accept_string ()
{
cout<<"\n Enter String :";
cin>>str;
}
void display_string()
{
cout<
String operator+(String x)//
Concatenating String
{
String s;
strcpy(s.str,str);
strcat(s.str,x.str);
return(s);
}
};
int main()
{
String str1, str2, str3;
str1.accept_string();
str2.accept_string();
cout<<"\n\n First String is : ";
str1.display_string();
cout<<"\n\n Second String is : ";
str2.display_string();
str3=str1+str2;
cout<<"\n\n Concatenated String is :";
str3.display_string();
return 0;
}
Output:
Enter String: COMPUTER
Enter String: SCIENCE
First String is: COMPUTER
Second String is: SCIENCE
Concatenated String is: COMPUTERSCIENCE
In simple words: The original code had small mistakes, like missing spaces or wrong operator symbols. The main issue was how it tried to join strings. The corrected code fixes these, especially the part that joins two strings together, making sure it works correctly.
π― Exam Tip: When debugging, always check for syntax errors first, then logic errors. For operator overloading, ensure the operator symbol (like `+` for concatenation) and its implementation correctly perform the desired operation, usually returning a new object for binary operations.
Question 5. Answer the questions based on the following program.
#include
#include
using namespace std;
class comp
{
public:
char s[10];
void getstring(char str[10])
{
strcpy(s,str);
}
void operator==(comp);
};
void comp::operator==(comp ob)
{
if(strcmp(s,ob.s)==0)
cout<<"\nStrings are Equal";
else
cout<<"\nStrings are not Equalβ;
}
int main()
{
comp ob, ob1;
char string1[10], string2[10];
cout<<"Enter First String:";
cin>>string1;
ob.getstring(string1);
cout<<"\nEnter Second String:";
cin>>string2;
ob1.getstring(string2);
ob==ob1;
return 0;
}
(i) Mention the objects which will have the scope till the end of the program.
(ii) Name the object which gets destroyed in between the program.
(iii) Name the operator which is overloaded and write the statement that invokes it.
(iv) Write out the prototype of the overloaded member function
(v) What types of operands are used for the overloaded operator?
(vi) Which constructor will get executed? Write the output of the program
Answer:
(i) Objects `ob` and `ob1` in the `main()` function will exist until the program finishes.
(ii) There is no object that specifically gets destroyed in the middle of the `main()` function's execution in this particular program. All objects created in `main` persist until `main` exits.
(iii) The operator overloaded is \( == \). The statement that uses it is `ob==ob1;`.
(iv) The prototype of the overloaded member function is: `void comp::operator==(comp);`
(v) User-defined data type `class (comp)` objects are used as operands.
(vi) No constructor is explicitly defined in the class. Therefore, a constructor that the compiler automatically creates (default constructor) will be used when the objects `ob` and `ob1` are made.
Output:
Enter First String:COMPUTER
Enter Second String:SCIENCE
Strings are not Equal
Output:
Enter First String:COMPUTER
Enter Second String:COMPUTER
Strings are Equal
In simple words: In this code, `ob` and `ob1` are the main things that exist for the whole program. The "equals" symbol (==) is changed to compare two string objects. When `ob==ob1` is used, it calls a special function to check if their strings are the same. Since we didn't write a setup function (constructor), the computer uses a basic one by itself.
π― Exam Tip: Remember that local objects usually live as long as the function they are in. When overloading operators, the prototype must match the syntax: `return_type class_name::operator_symbol (argument_list);`.
Question 1. The number and types of a function's parameters are called the _________
(a) overload resolution
(b) function's signature
(c) function overloading
(d) operator overloading
Answer: (b) function's signature
In simple words: The unique way a function is identified by how many inputs it takes and what kind of inputs they are is called its signature.
π― Exam Tip: Function signature is crucial for overloading, as it tells the compiler which specific function to use when multiple functions share the same name.
Question 2. In C++, polymorphism is achieved through _________ overloading.
(a) Function
(b) Operator
(c) Operand
(d) Either A or B
Answer: (d) Either A or B
In simple words: In C++, polymorphism means using functions or operators differently based on the situation, and this is done by function overloading or operator overloading.
π― Exam Tip: Polymorphism allows a single interface to be used for different underlying forms, and overloading is a key way to implement this in C++.
Question 3. The return type of overloaded functions is not considered for overloading same _________.
(a) polymorphism
(b) prototype
(c) data type
(d) overloading
Answer: (c) data type
In simple words: When you overload functions, only the number and types of the inputs (parameters) matter, not what kind of value the function gives back (return type).
π― Exam Tip: Remember, function overloading depends solely on the parameter list's number and type, not the return type. This is a common point of confusion.
Question 4. The number and types of a function's parameters are called the function's _________.
(a) Signature
(b) Syntax
(c) Either A or B
(d) None of these
Answer: (a) Signature
In simple words: The specific details of a function, like how many inputs it needs and what kind of inputs they are, make up its signature.
π― Exam Tip: Understand that the function's signature is fundamental for the compiler to distinguish between multiple functions with the same name during overloading.
Question 5. The mechanism of giving special meaning to an operator is known as _________.
(a) operator overloading
(b) parameter
(c) function overloading
(d) polymorphism
Answer: (a) operator overloading
In simple words: When you make standard symbols, like `+` or `-`, do special actions for your own custom data types, it's called operator overloading.
π― Exam Tip: Operator overloading enhances the usability of custom data types by allowing them to work with standard operators, making code more readable and intuitive.
Question 6. _________ overloading is not only implementing polymorphism but also reduces the number of comparisons in a program and makes the program execute faster.
(a) Function
(b) Operator
(c) Operand
(d) Either A or B
Answer: (a) Function
In simple words: Using function overloading helps make the code more flexible (polymorphism) and can also help the program run quicker by needing fewer checks inside.
π― Exam Tip: Function overloading allows for code reuse and simplifies the interface for a set of operations, which can indirectly lead to more efficient code.
Question 7. The overloaded operator is given using the keyword _________ followed by an _________.
(a) operator
(b) data type
(c) object
(d) function
Answer: (a) operator
In simple words: To change what an operator does, you use the special word `operator` then the symbol of the operator you want to change, like `operator+`.
π― Exam Tip: The `operator` keyword is mandatory for defining operator overloading functions in C++.
Question 8. The _________ of overloaded functions are not considered as part of the parameter list in function overloading.
(a) arguments
(b) default arguments
(c) data
(d) None of these
Answer: (b) default arguments
In simple words: When a function has some inputs that already have a default value, these default inputs are not used to tell overloaded functions apart. Only the number and types of other inputs matter.
π― Exam Tip: When deciding if functions are overloaded, ignore any default values for parameters; the compiler only looks at the required parameters and their types.
Question 9. The _________ data type of overloaded functions are not considered for overloading the same data type.
(a) return type
(b) arguments
(c) data
(d) None of these
Answer: (a) return type
In simple words: For functions to be overloaded, they must have different input types or numbers. What they give back (their return type) does not matter for overloading.
π― Exam Tip: A common mistake is to try overloading based only on return type; this will cause a compilation error. Overloading must involve differences in parameters.
Question 10. The overloaded function must differ in _________.
(a) the number of its arguments
(b) data types
(c) Either A or B
(d) None of these
Answer: (c) Either A or B
In simple words: To overload a function, its inputs must be different, either by having a different count of inputs or by having inputs of different types.
π― Exam Tip: This rule is central to function overloading: the compiler needs a clear way to distinguish which version of the function to call based on the arguments provided.
Question 11. _________ overloading provides the flexibility of creating multiple types of objects for a class,
(a) Constructor
(b) Destructor
(c) Member function
(d) None of these
Answer: (a) Constructor
In simple words: When a class has many different ways to set up (construct) its objects, it's called constructor overloading. This makes it flexible to create objects in various ways.
π― Exam Tip: Constructor overloading is a special type of function overloading that allows objects to be initialized with different sets of arguments, enhancing class usability.
Question 12. Compiler identifies a given member function is a constructor by its _________.
(a) name
(b) return type
(c) Either A or B
(d) None of these
Answer: (a) name
In simple words: The computer knows a function is a constructor because it has the exact same name as the class it belongs to. Constructors never have a return type.
π― Exam Tip: Constructors are special member functions primarily used for initializing objects; they always have the same name as the class and no return type.
Question 13. The term overloading refers to giving additional functionality to the normal C++ operators.
(a) Function
(b) Operator
(c) Operand
(d) Either A or B
Answer: (b) Operator
In simple words: Operator overloading means changing what regular symbols like `+` or `-` do when you use them with your own special data types.
π― Exam Tip: Operator overloading allows C++ operators to be redefined for user-defined types, making expressions with objects feel more natural and intuitive.
Question 14. _________ operator can not be overloaded.
(a) scope operator::
(b) sizeof
(c) member selector.
(d) All the options
Answer: (d) All the options
In simple words: There are some special symbols in C++, like `::` (scope operator), `sizeof`, and `.` (member selector), that you cannot change what they do.
π― Exam Tip: Be aware of the operators that cannot be overloaded. These are typically operators that have fundamental, non-negotiable meanings in C++ syntax.
Question 15. _________ operator can not be overloaded.
(a) Member pointer selector
(b) Ternary operator ?:
(c) Both A and B
(d) None of these
Answer: (c) Both A and B
In simple words: You cannot change what the member pointer selector (`.*` and `->*`) and the ternary operator (`?:`) do for your own classes.
π― Exam Tip: Certain operators, like the member pointer selector and the ternary operator, are intrinsically tied to C++'s core language features and cannot be customized through overloading.
Question 16. _________ can be Overloaded.
(a) User-defined types (objects)
(b) Literals
(c) Identifiers
(d) None of these
Answer: (a) User-defined types (objects)
In simple words: You can only change how operators work when you use them with your own custom data types or objects. You cannot change how they work with basic things like numbers or single characters.
π― Exam Tip: Operator overloading is specifically designed to extend the functionality of operators to custom classes, not to change the behavior of operators for built-in types.
Very Short Answers (2 Marks)
Question 1. Give the syntax for operator overloading.
Answer: The general way to write the syntax for operator overloading is:
`ReturnType classname :: operator OperatorSymbol (argument list)`
`{`
`// Function body`
`}`
For example, for a `Deposit` class, overloading the `+` operator might look like: `Deposit Deposit::operator+(Deposit dl);` This allows you to add two `Deposit` objects using the `+` symbol.
In simple words: To change what an operator does, you write a special function using the word `operator` followed by the symbol you want to change, like `operator+`. This function belongs to a class and tells the computer how to use that operator with objects of that class.
π― Exam Tip: When writing the syntax, pay close attention to the `operator` keyword, the `::` scope resolution operator, and the correct placement of the `OperatorSymbol` and `argument list`.
Question 2. How polymorphism is applied in C++?
Answer: In C++, polymorphism means one name, many forms. It is put into practice using two main methods: function overloading and operator overloading. Function overloading allows multiple functions to have the same name but different parameters, letting the compiler decide which one to call based on the arguments. Operator overloading allows operators like `+` or `-` to have different meanings when used with different types of data, especially user-defined types. This gives more flexibility and makes the code easier to read, as the same operation symbol can apply to various data types.
In simple words: In C++, polymorphism makes things behave differently based on context. It works by having many functions with the same name but different inputs (function overloading) or by making symbols like `+` do special things for custom objects (operator overloading).
π― Exam Tip: When discussing polymorphism in C++, always mention both function overloading and operator overloading as they are the primary mechanisms for achieving it.
Question 4. What is a function signature?
Answer: A function signature is the unique identifier for a function, made up of its name, the number of its parameters, and the data types of those parameters in their specific order. It does not include the function's return type or default arguments. The compiler uses this signature to tell different overloaded functions apart and decide which one to call when the function is used. For instance, `void print(int a, float b)` has a different signature from `void print(float a, int b)`, even though they share the same name.
In simple words: A function's signature is like its ID card, showing its name, how many inputs it needs, and what kind of inputs they are. This helps the computer pick the right function when many have the same name.
π― Exam Tip: Always clearly state that the function signature includes the function name and its parameter list (number, type, and order), but explicitly excludes the return type and default arguments.
Short Answers (3 Marks)
Question 1. How does the compiler determine the appropriate function in overloading?
Answer: When a program calls an overloaded function, the compiler needs to decide which specific version of that function to use. It does this through a process called overload resolution. The compiler looks at the function's name and then compares the types and number of arguments provided in the function call with the parameter lists (signatures) of all available overloaded functions. It tries to find the best match. This means it checks if the data types of the arguments in the call match the parameter types in any of the function definitions. The goal is to find the most fitting definition that was specified for the function. For example, if there are `print(int)` and `print(float)`, and you call `print(5)`, the compiler will choose `print(int)`. This careful selection process ensures the correct function version is executed.
In simple words: The computer decides which overloaded function to use by looking at the function's name and comparing the inputs given with the inputs each function expects. It picks the one that matches best.
π― Exam Tip: Emphasize that overload resolution is based on matching the arguments in the function call to the parameters in the function definitions, prioritizing the closest type match.
Question 2. Explain overload resolution.
Answer: Overload resolution is the process used by a C++ compiler to determine which particular function or operator to invoke when there are multiple functions or operators with the same name but different parameter lists (i.e., overloaded functions or operators). When an overloaded function is called, the compiler examines the arguments provided in the call. It then compares these arguments with the parameter types and number of each available overloaded definition. The compiler tries to find the "best" match among the candidates, often involving implicit type conversions if an exact match isn't found. The aim is to select the most appropriate definition that perfectly aligns with the given argument types, or can be converted to them with the fewest steps. This process ensures that the correct version of an overloaded function or operator is executed based on the context of its usage.
In simple words: Overload resolution is how the computer chooses the correct function or operator when several options exist with the same name. It checks the inputs you give and finds the best match from all the possible choices.
π― Exam Tip: Highlight that overload resolution is an automatic compiler process and that it seeks the "best" match based on parameter types, possibly involving standard type conversions.
Question 3. Write operator overloading syntax.
Answer: Operator overloading provides a way to define how C++ operators work with custom data types. The basic syntax involves specifying the return type, class name, the `operator` keyword, the operator symbol, and any arguments.
In simple words: This is how you write the basic structure for changing what an operator does for your own custom class. It tells the computer what kind of result to expect, which class it belongs to, and which operator is being changed.
| Keyword | Operator to be overloaded |
|---|---|
| Return Type classname :: operator Operator Symbol (argument list) | |
| { | |
| \Function body | |
| } |
π― Exam Tip: Remember that `operator` is a keyword, and the operator symbol (`+`, `-`, `*`, etc.) directly follows it. The `classname ::` part is essential for defining the operator outside the class.
Question 4. Write a program to implement function overloading.
Answer: This program demonstrates function overloading by defining three `print` functions that take different data types (int, double, string) as input. The compiler chooses the correct `print` function based on the type of argument passed during the function call.
In simple words: Here is a computer program that shows how you can have many functions with the same name, but they work differently depending on what kind of information you give them. Like having a "print" button that prints numbers, decimal numbers, or words, all from the same button name.
Program:
#include <iostream>
using namespace std;
void print(int i)
{
cout<< " It is integer" << i <<endl;
}
void print(double f)
{
cout<< " It is float" << f <<endl;
}
void print(string c)
{
cout<< " It is string " << c <<endl;
}
int main()
{
print(10);
print(10.10);
print("Ten");
return 0;
}
Output:
It is integer 10
It is float 10.1
It is string Ten
π― Exam Tip: When writing overloaded functions, ensure their parameter lists are distinct, as this is how the compiler differentiates between them. Small variations in parameters, like different data types or number of arguments, are key.
Explain In Detail (5 Marks)
Question 1. Write a program to implement function overloading.
Answer: This program illustrates function overloading with three `add` functions that have the same name but different parameter lists. One `add` function takes two `long` integers, another takes three `long` integers, and the third takes two `float` numbers. This demonstrates how C++ can select the appropriate function based on the number and type of arguments provided during a call.
In simple words: This program shows how to use the same function name, `add`, for different tasks. One `add` function sums two whole numbers, another sums three whole numbers, and a third sums two decimal numbers. The computer picks the right `add` function depending on what numbers you give it.
Program:
#include <iostream>
using namespace std;
long add(long, long);
long add(long,long,long);
float add(float, float);
int main()
{
long a, b, c,d;
float e, f, g;
cout << "Enter three integers\n";
cin >> a >> b>>c;
//number of arguments different but same
data type
d=add(a,b,c);
cout << "Sum of 3 integers: " << d << endl;
cout << "Enter two integers\n";
cin >> a >> b;
//two arguments data type same with above function call and different with
below function call
c = add(a, b);
cout << "Sum of 2 integers: " << c << endl;
cout << "Enter two floating point numbers\n";
cin >> e >> f;
//two arguments similar to the above function call but data type different
g = add(e, f);
cout << "Sum of floats: " << g << endl;
}
long add(long c, long g)
{
long sum;
sum = c + g;
return sum;
}
long add(long c, long g,long h)
{
long sum;
sum = c + g+h;
return sum;
}
float add(float c, float g)
{
float sum;
sum = c + g;
return sum;
}
Output:
Enter three integers
3 4 5
Sum of 3 integers: 12 Enter two integers
4 6
Sum of 2 integers: 10
Enter two floating-point numbers
2.1 3.1
Sum of floats: 5.2
π― Exam Tip: Pay close attention to the argument list (number and data types of parameters) as this is what the compiler uses for "overload resolution" - deciding which function to call.
Question 2. Write the coding for the following output using constructor overloading.
Answer: This program demonstrates constructor overloading within a class named `add`. It defines three constructors: a default constructor (no parameters), a parameterized constructor (two integers), and a copy constructor (an existing `add` object). This allows for flexible object creation and initialization, which is a key feature in C++.
In simple words: This code shows how to make special functions called "constructors" that build new objects. We have three types: one that builds a basic object, one that builds it with starting numbers, and one that makes an exact copy of another object. This gives us many ways to set up our objects.
Output:
Constructor without parameters..
Parameterized constructor...
Copy Constructor...
Enter data... 20 30
Object a:
The numbers are..20 30
The sum of the numbers are.. 50
Object b:
The numbers are.. 10 20
The sum of the numbers are.. 30
Object c:
The numbers are.. 10 20
The sum of the numbers are.. 30
#include
using namespace std;
class add
{
int num1, num2, sum;
public:
add()
{
cout << "\n Constructor without parameters...";
num1 = 0;
num2 = 0;
sum = 0;
}
add (int s1, int s2)
{
cout << "\n Parameterized constructor...";
num1 = s1;
num2=s2;
sum=0;
}
add (add &a)
{
cout << "\n Copy Constructor...";
num1 = a.num1;
num2 = a.num2;
sum = 0;
}
void getdata()
{
cout << "\n Enter data ..."; cin>>num 1 >> num2;
}
void addition()
{
sum=num 1 + num2;
}
void putdata()
{
cout << "\n The numbers are..";
cout << "\n The sum of the numbers are.." << sum;
}
};
int main()
{
add a, b (10, 20), c(b);
a. getdata();
a. addition();
b. addition();
c. addition();
cout << "\n Object a : ";
a. putdata();
cout << "\n Object b : ";
b. putdata();
cout << "\n Object c..";
c. putdata();
return 0;
}
π― Exam Tip: Constructors are vital for object initialization. A default constructor takes no arguments, a parameterized constructor takes arguments, and a copy constructor initializes an object using another object of the same class.
Question 3. Write a program to find complex number addition and subtraction using binary operator overloading.
Answer: This program demonstrates how to overload the binary `+` and `-` operators to perform addition and subtraction of complex numbers. By defining these operators within the `complex` class, we can use standard arithmetic syntax (`c1 + c2`) to manipulate complex number objects, making the code more readable and intuitive.
In simple words: This program teaches how to make the plus (+) and minus (-) symbols work for "complex numbers" (numbers with a real and imaginary part). So, instead of using special functions, you can just write `complex1 + complex2` or `complex1 - complex2` to add or subtract them, making the code easier to understand.
Program:
//Complex number addition and subtraction
#include<iostream>
using namespace std;
class complex
{
int real,img;
public:
void read()
{
cout<<"\nEnter the REAL PART : ";
cin>> real;
cout<<"\nEnter the IMAGINARY PART : ";
cin>>img;
}
complex operator+(complex c2)
{
complex c3;
c3.real=real+c2.real;
c3.img=img+c2.img;
return c3;
}
complex operator-(complex c2)
{
complex c3;
c3.real=real-c2.real;
c3.img=img-c2.img;
return c3;
}
void display()
{
cout<<real<<"+"<}
};
int main()
{
complex c1,c2,c3;
int choice, cont;
do
{
cout<<"\t\tCOMPLEX NUMBERS\n";
cout<<"1.ADDITION\n2.SUBTRACTION\n\n";
cout<<"\nEnter your choice :";
cin>> choice;
if(choice==1|| choice==2)
{
cout<<"\n\nEnter the First Complex
Number";
c1.read();
cout<<"\n\nEnter the Second Complex
Number";
c2.read();
}
switch(choice)
{
// binary + overloaded
case 1: c3=c1+c2;
cout<<"\n\nSUM = ";
c3.display();
break;
case 2: c3=c1-c2; // binary -overloaded
cout<<"\n\nResult = ";
c3.display();
break;
default: cout<<"\n\nUndefined Choice";
}
cout<<"\n\nDo You Want to Continue?(1-Y,0-N)";
cin>> cont;
}while(cont==1);
return 0;
}
Output:
COMPLEX NUMBERS
1.ADDITION
2.SUBTRACTION
Enter your choice : 1
Enter the First Complex Number
Enter the REAL PART : 3
Enter the IMAGINARY PART: 4
Enter the Second Complex Number
Enter the REAL PART: 5
Enter the IMAGINARY PART: 8
SUM = 8+12i,
Do You Want to Continue?(1-Y,0-N)1
COMPLEX NUMBERS
1.ADDITION
2.SUBTRACTION
Enter your choice: 2
Enter the First Complex Number
Enter the REAL PART: 8
Enter the IMAGINARY PART: 10
Enter the Second Complex Number
Enter the REAL PART: 4
Enter the IMAGINARY PART: 5
Result = 4+5i
Do You Want to Continue? (1-Y,0-N)0
π― Exam Tip: When overloading binary operators, ensure the operator function correctly combines two objects. For complex numbers, this means adding/subtracting their real and imaginary parts separately.
Question 4. Write a program for concatenation of string using operator overloading.
Answer: This program shows how to overload the binary `+` operator for string concatenation. By defining an `operator+` function within the `strings` class, we can combine two string objects using the `+` symbol, which makes string manipulation more intuitive and consistent with built-in data types.
In simple words: This program makes the plus (+) sign work to join two "string" objects (which are like collections of letters or words). Instead of using a special function to stick words together, you can simply write `string1 + string2` to combine them.
Program:
#include<string.h>
#include <iostream >
using namespace std;
class strings
{
public:
char s[20];
void getstring(char str[])
{
strcpy(s,str);
}
void operator+(strings);
};
void strings: :operator+(strings ob)
{
strcat(s,ob.s);
cout<<"\nConcatnated String is:"<<s;
}
int main()
{
strings ob1, ob2;
char stringl[10], string2[10];
cout<<"\nEnter First String:";
cin>>string1;
ob1.getstring(string1);
cout<<"\nEnter Second String:";
cin>>string2;
ob2.getstring(string2);
//Calling + operator to Join/Concatenate strings
ob1+ob2;
return 0;
}
Output:
Enter First String: COMPUTER
Enter Second String: SCIENCE
Concatenated String is: COMPUTERSCIENCE
π― Exam Tip: When overloading operators for classes like strings, be mindful of buffer overflows if fixed-size character arrays are used. Ensure the destination array is large enough to hold the concatenated string.
Case Study
Question. Create a class 'Deposit' with a data member named 'amount' with an initial value of Rs.500. Now make three constructors of this class as follows: 1. without any parameter - no amount will be added to the Kitty Bank 2. has a parameter which is the amount that will be added to the Kitty Bank 3. whenever an amount is added an additional equal amount will be deposited automatically. Create an object of the 'Deposit' and display the final amount in the Kitty Bank.
Answer: This program defines a `Deposit` class to simulate a Kitty Bank with an initial amount of Rs.500. It uses constructor overloading to provide three ways to deposit money: a default constructor (initial Rs.500, no added amount), a parameterized constructor (Rs.500 plus a specified amount), and a special parameterized constructor (Rs.500 plus a specified amount and an equal additional amount). This demonstrates flexible object initialization based on different deposit scenarios.
In simple words: This code creates a "Deposit" system for a Kitty Bank. It starts with Rs.500 and lets you add money in three ways: just keeping the Rs.500, adding a specific amount you choose, or adding an amount you choose plus a bonus matching that amount. This shows how to set up the bank's starting money in different ways.
Program:
using namespace std;
#include<iostream>
class Deposit
{
public:
int amount;
Deposit()
{
amount = 500;
}
Deposit(int a)
{
amount = 500 + a;
}
Deposit(int a, int b)
{
amount = 500 + a + b;
}
void display()
{
cout<<amount;
}
};
int main()
{
Deposit D1;
int amt;
cout<<"\nEnter amount to deposit";
cin>>amt;
cout<<"\nInitial Amount in the Bank
Rs." <<D1.amount;
Deposit D2(amt);
cout<<"\nAmount in the Bank after deposit the amount is Rs."<<D2.amount;
Deposit D3(amt,amt);
cout<<"\nAmount in the Bank after deposit with addition equal amount deposit
Rs."<<D3.amount;
}
Output:
Enter amount to deposit 1000
Initial Amount in the Bank Rs.500
Amount in the Bank after deposit the amount is Rs.1500
Amount in the Bank after deposit with addition equal amount deposit Rs.2500
π― Exam Tip: Constructor overloading is ideal for providing multiple ways to initialize an object, allowing different initial states or configurations. Remember that each overloaded constructor must have a unique parameter list.
(The specified page range, page 43 to page 43, contains only navigation links, a watermark, and footer information, all of which are to be ignored according to the content processing rules. No educational content (questions or answers) was found within this range.)Free study material for Computer Science
TN Board Solutions Class 11 Computer Science Chapter 15 Polymorphism
Students can now access the TN Board Solutions for Chapter 15 Polymorphism prepared by teachers on our website. These solutions cover all questions in exercise in your Class 11 Computer Science textbook. Each answer is updated based on the current academic session as per the latest TN Board syllabus.
Detailed Explanations for Chapter 15 Polymorphism
Our expert teachers have provided step-by-step explanations for all the difficult questions in the Class 11 Computer Science chapter. Along with the final answers, we have also explained the concept behind it to help you build stronger understanding of each topic. This will be really helpful for Class 11 students who want to understand both theoretical and practical questions. By studying these TN Board Questions and Answers your basic concepts will improve a lot.
Benefits of using Computer Science Class 11 Solved Papers
Using our Computer Science solutions regularly students will be able to improve their logical thinking and problem-solving speed. These Class 11 solutions are a guide for self-study and homework assistance. Along with the chapter-wise solutions, you should also refer to our Revision Notes and Sample Papers for Chapter 15 Polymorphism to get a complete preparation experience.
FAQs
The complete and updated Samacheer Kalvi Class 11 Computer Science Solutions Chapter 15 Polymorphism is available for free on StudiesToday.com. These solutions for Class 11 Computer Science are as per latest TN Board curriculum.
Yes, our experts have revised the Samacheer Kalvi Class 11 Computer Science Solutions Chapter 15 Polymorphism as per 2026 exam pattern. All textbook exercises have been solved and have added explanation about how the Computer Science concepts are applied in case-study and assertion-reasoning questions.
Toppers recommend using TN Board language because TN Board marking schemes are strictly based on textbook definitions. Our Samacheer Kalvi Class 11 Computer Science Solutions Chapter 15 Polymorphism will help students to get full marks in the theory paper.
Yes, we provide bilingual support for Class 11 Computer Science. You can access Samacheer Kalvi Class 11 Computer Science Solutions Chapter 15 Polymorphism in both English and Hindi medium.
Yes, you can download the entire Samacheer Kalvi Class 11 Computer Science Solutions Chapter 15 Polymorphism in printable PDF format for offline study on any device.