C++ Programming - OOPS Concepts - Discussion
Discussion Forum : OOPS Concepts - General Questions (Q.No. 5)
5.
Which of the following concepts means determining at runtime what method to invoke?
Discussion:
37 comments Page 1 of 4.
Gagan said:
1 decade ago
Static Typing:
Static typed programming languages are those in which variables need not be defined before they're used. This implies that static typing has to do with the explicit declaration (or initialization) of variables before they're employed. Java is an example of a static typed language; C and C++ are also static typed languages. Note that in C (and C++ also), variables can be cast into other types, but they don't get converted; you just read them assuming they are another type.
Static typing does not imply that you have to declare all the variables first, before you use them; variables maybe be initialized anywhere, but developers have to do so before they use those variables anywhere. Consider the following example:
/* C code */
static int num, sum; // explicit declaration
num = 5; // now use the variables
sum = 10;
sum = sum + num;
The above code fragment is an example of how variable declaration in static typed languages generally appears. Note that in the above code, static has nothing to do with static typing; it has been used along with int only to initialize num and sum to zero.
Dynamic Typing:
Dynamic typed programming languages are those languages in which variables must necessarily be defined before they are used. This implies that dynamic typed languages do not require the explicit declaration of the variables before they're used. Python is an example of a dynamic typed programming language, and so is PHP. Consider the following example:
/* Python code */
num = 10 // directly using the variable
In the above code fragment, we have directly assigned the variable num the value 10 before initializing it. This is characteristic to dynamic typed programming languages.
Static typed programming languages are those in which variables need not be defined before they're used. This implies that static typing has to do with the explicit declaration (or initialization) of variables before they're employed. Java is an example of a static typed language; C and C++ are also static typed languages. Note that in C (and C++ also), variables can be cast into other types, but they don't get converted; you just read them assuming they are another type.
Static typing does not imply that you have to declare all the variables first, before you use them; variables maybe be initialized anywhere, but developers have to do so before they use those variables anywhere. Consider the following example:
/* C code */
static int num, sum; // explicit declaration
num = 5; // now use the variables
sum = 10;
sum = sum + num;
The above code fragment is an example of how variable declaration in static typed languages generally appears. Note that in the above code, static has nothing to do with static typing; it has been used along with int only to initialize num and sum to zero.
Dynamic Typing:
Dynamic typed programming languages are those languages in which variables must necessarily be defined before they are used. This implies that dynamic typed languages do not require the explicit declaration of the variables before they're used. Python is an example of a dynamic typed programming language, and so is PHP. Consider the following example:
/* Python code */
num = 10 // directly using the variable
In the above code fragment, we have directly assigned the variable num the value 10 before initializing it. This is characteristic to dynamic typed programming languages.
(2)
Kandrasai said:
10 years ago
Binding means, linking of a procedural code to its functional call. During inheritance, when we are having the base and derived classes with same function name, at that time it may lead to the confusion of the compiler to link its exact procedural code. So we use the key word "virtual" to base class function.
So the compiler postpones the linking of procedural code for that one during the compile time. And binds its procedural code lately, which is called as "late or dynamic or run time binding".
So the compiler postpones the linking of procedural code for that one during the compile time. And binds its procedural code lately, which is called as "late or dynamic or run time binding".
(6)
Srikanth said:
1 decade ago
I don't agree with Vairakkani.
Dynamic means Runtime. Whereas static means Compile time.
Binding can be defined as the association between (link) function call to a function definition.
Dynamic binding means. The association (link) of function call to a function definition during runtime.
Dynamic means Runtime. Whereas static means Compile time.
Binding can be defined as the association between (link) function call to a function definition.
Dynamic binding means. The association (link) of function call to a function definition during runtime.
Alok singh chauhan said:
1 decade ago
Well if we talk about run time(dynamic) binding and static binding. Then,
Run time binding is one where function is select at running the program.
Eg - virtual functions.
Static binding is one where the object is bound to function call.
Eg - function overloading and operator overloading.
Run time binding is one where function is select at running the program.
Eg - virtual functions.
Static binding is one where the object is bound to function call.
Eg - function overloading and operator overloading.
Prashant said:
1 decade ago
Dynamic loading is a mechanism by which a computer program can, at run time, load a library (or other binary) into memory, retrieve the addresses of functions and variables contained in the library, execute those functions or access those variables, and unload the library from memory.
Kavita bangar said:
1 decade ago
Prashant is correct!
In C++ you can have an array of base classes but you can call different functions of the derived class by assigning the derived class objects addresses by using virtual functions-this is dynamic binding. If the methods are virtual then this is dynamic binding.
In C++ you can have an array of base classes but you can call different functions of the derived class by assigning the derived class objects addresses by using virtual functions-this is dynamic binding. If the methods are virtual then this is dynamic binding.
Shaikh Moin Rukmoddin said:
1 decade ago
In C++ you can have an array of base classes but you can call different functions of the derived class by assigning the derived class objects addresses by using virtual functions - this is dynamic binding. If the methods are virtual then this is dynamic binding.
Madhu said:
10 years ago
@Guru,
Dynamic binding is a technique where function call could be linked to its code at run time. We can see it in inheritance, etc.
But dynamic loading is a mechanism undergone by the system where loading of libraries, functions and their data takes place.
Dynamic binding is a technique where function call could be linked to its code at run time. We can see it in inheritance, etc.
But dynamic loading is a mechanism undergone by the system where loading of libraries, functions and their data takes place.
(3)
Vivek kumar said:
1 decade ago
In C++ you can have an array of base classes but you can call different functions of the derived class by assigning the derived class objects addresses by using virtual functions-this is dynamic binding. If the methods are virtual then this is dynamic binding.
Rohit said:
1 decade ago
Why not the dynamic typing is correct ? If we see the example of function overloading then ther is dynamic linking on the basis of data types ? So dynamic lynking may be correct. Please answer.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers