Polymorphism: book back answers

14 solved questions from the end of this chapter, Class 11 Computer Science, Tamil Nadu State Board. Each answer is checked against the textbook, and you can open the page that proves it.

← Notes and quiz for Polymorphism

SECTION – A Choose the correct answer

  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
    Try it, then show the answer

    (A) Function Overloading

    An overloaded function has more than one distinct meaning.

    From the book: “an ‘overloaded function’ refers to a function having more than one distinct meaning”

  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
    Try it, then show the answer

    (C) Function Overloading

    The chapter notes that function overloading reduces the number of comparisons in a program.

    From the book: “Function overloading is not only implementing polymorphism but also reduces the number of comparisons in a program”

  3. void dispchar(char ch=’$’,int size=10) for(int i=1;i<=size;i++) cout<<ch; How will you invoke the function dispchar() for the following input? To print $ for 10 times

    • (A) dispchar();
    • (B) dispchar(ch,size);
    • (C) dispchar($,10);
    • (D)dispchar(‘$’,10 times);
    Try it, then show the answer

    (A) dispchar();

    Both parameters have default values, so calling the function without arguments uses '$' and 10.

    From the book: “The default arguments of overloaded functions are not considered as part of the parameter list in function overloading.”

  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.
    Try it, then show the answer

    (B) The return type is also considered for overloading a function.

    Return type is not considered when deciding whether functions are overloaded; they must differ in argument number or types.

    From the book: “The return type of overloaded functions are not considered for overloading same data type”

  5. Which of the following is invalid prototype for function overloading (A) void fun (intx); void fun (char ch) ; (B) void fun (intx); void fun (inty); (C) void fun (double d); void fun (char ch); (D) void fun (double d); void fun (inty);

    • (A) void fun (intx); void fun (char ch) ;
    • (B) void fun (intx); void fun (inty);
    • (C) void fun (double d); void fun (char ch);
    • (D) void fun (double d); void fun (inty);
    Try it, then show the answer

    (B) void fun (intx); void fun (inty);

    These prototypes have the same name and parameter type, so their signatures do not differ.

    From the book: “The overloaded function must differ in the number of its arguments or data types”

SECTION-B

  1. What is function overloading?

    Try it, then show the answer

    Function overloading is when two or more functions in the same scope share the same name but have different parameters.

    The shared function name can process data in more than one form because the parameters differ.

    From the book: “two or more functions in the same scope share the same name but their parameters are different”

  2. List the operators that cannot be overloaded.

    Try it, then show the answer

    Scope resolution operator (::), sizeof, member selector (.), member pointer selector (✳), and ternary operator (?:).

    These are the operators listed in the chapter as not overloadable.

    From the book: “Scope operator (::) • Sizeof • Member selector (.) • Member pointer selector (✳) • Ternary operator (?:)”

  3. class add{int x; public: add(int)}; Write an outline definition for the constructor.

    Try it, then show the answer

    add::add(int a) { x = a; }

    A constructor definition uses the class name and accepts the integer argument, which can initialize x.

    From the book: “A class can have more than one constructor with different signature.”

  4. Does the return type of a function help in overloading a function?

    Try it, then show the answer

    No. The return type does not help in overloading a function.

    Overloaded functions must differ in their argument number or types; return type is not considered.

    From the book: “The return type of overloaded functions are not considered for overloading same data type”

  5. What is the use of overloading a function?

    Try it, then show the answer

    It lets functions with the same name process different forms of data, and reduces the number of function names a programmer must remember.

    The suitable function definition is selected based on the arguments used in the call.

    From the book: “It also helps the programmer by reducing the number of function names to be remembered.”

SECTION-C Short Answers

  1. How does a compiler decide as to which function should be invoked when there are many functions? Give an example.

    Try it, then show the answer

    The compiler compares the types of the supplied arguments with the parameter types in the overloaded definitions and selects the most appropriate one. For example, print(10) selects print(int), while print(10.10) selects print(double).

    This selection process is called overload resolution.

    From the book: “the compiler determines the most appropriate definition to use, by comparing the argument types you have used to call the function”

  2. What is operator overloading? Give some examples of operators which can be overloaded.

    Try it, then show the answer

    Operator overloading gives an existing C++ operator additional, user-defined meaning. Examples include +, ++, -, +=, -=, *, < and >.

    For example, the + operator can be given a meaning for adding complex numbers or concatenating strings.

    From the book: “giving additional functionality to the normal C++ operators like +,++,−,—,+=,−=,*.<,>”

  3. Discuss the benefits of constructor overloading ?

    Try it, then show the answer

    Constructor overloading provides flexibility in creating multiple types of objects for a class.

    Different constructor signatures allow objects to be created with different sets of arguments.

    From the book: “Constructor overloading provides flexibility of creating multiple type of objects for a class.”

  4. class sale ( int cost, discount ;public: sale(sale &); Write a non inline definition for constructor specified;

    Try it, then show the answer

    sale::sale(sale &s) { cost = s.cost; discount = s.discount; }

    This is a non-inline copy-constructor definition that copies the two data members from the supplied sale object.

    From the book: “add (add &a) { cout<<"\n Copy Constructor ... "; num1= a.num1; num2=a.num2;”

Next chapterInheritance