10- a) What construct a programming language requires to support Polymorphic Var
ID: 3740559 • Letter: 1
Question
10- a) What construct a programming language requires to support Polymorphic Variables?
b) When does the binding of Polymorphic variables to their values can happen?
c) Use the code in question 9-c (above) to write an example of a polymorphic variable. (Your example does not have to completely follow the C++ syntax. What is important is being able to show the concept of polymorphic variables in your example)
3- a) What is the constructor of a class?
b) In some programming languages the class constructor must have a specific name while in some other languages, the class constructor can have any name. Describe the cons and pros of each approach.
Explanation / Answer
10-a) Polymorphic means having many forms. "Function" construct .For example a function should return int value means that it can operate on either string variables or int variables based on function definition.
b)either at the time of compilation time if values are provided means initialization of variables
at the time of run time if values are entered at the time of run time
3a) Constructor is a special type of sub routine used to create the objects.
3b) Most of the programming languages have same name as class name but very few languages has different names for constructor and classes.
In the case of having same name to constructor and class has advanatage of object creation without providing extra code to specifying it as a constructor
But, in case of having different names to constructor and class has disadvantage that compiler doesn't know which function is executed when object created and also values that are present in function are to be set.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.