answersLogoWhite

0


Best Answer

Of course not.

User Avatar

Wiki User

15y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Addition of methods into object at runtime?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Why do you need runtime polymorphismis inheritance necessary for it?

Runtime polymorphism is required because accessing the runtime type of an object is expensive. And yes, inheritance is required for it because polymorphism is enabled through virtual functions. It is not the programmer's responsibility to determine the runtime type of an object because that information should be provided by the object's own virtual table. Thus when you implicitly invoke a virtual method of the base class, you rightly expect most-derived method to be executed, even when you cannot know in advance the exact type of the derivative -- all you know is that it is a type of base class. And that's all you need for polymorphism to work. If you ever find yourself having to turn on the runtime type of an object in order to invoke one of its methods, then you need to seriously consider redesigning your classes. How can your code possibly cope with a runtime type it has no knowledge of, such as a derived object of a class created by a third-party? In those instances you would have no way of knowing what specific methods were available. But with virtual methods there is no need to know. You simply invoke the generic virtual methods of your base class and you automatically get specific behaviour; all your derivatives do whatever they've been implemented to do, whether it is to invoke the base class method explicitly, or provide an override, or indeed both!


Can a static function be made virtual?

No. Virtual functions are invoked according to the runtime type of the object. That is; the most-derived override is automatically invoked even when the runtime type of the object cannot be determined at compile time. This is achieved through the object's virtual table. Static methods do not have any object associated with them; they can be invoked even when no object of the type exists. Without an object, there can be no virtual table. Thus static functions cannot be virtual. They are mutually exclusive concepts.


Who invoke main function in java?

The Java Runtime Environment invokes main methods.


How can you force the garbage collector to run?

You can't force it but you call System.gc(), which is a "hint" to the runtime engine that now might be a good time to run the GC. But garbage collection using this method is not guaranteed to be done immediately. there is another way to explicitly call the gc(). this method is also define in Runtime class of package java.lang. But u can not create a direct object of class Runtime like Runtime a = new Runtime(); //wrong For that u have to call the method getRuntime() which is static and it is also define in Runtime class the way to create object is Runtime run; //right run = Runtime.getRuntime(); //right now u can call the gc() through the "run " Object. like run.gc(); //right


Is there a if exists statement in Java programming?

In java you will be handling objects. An object, for example, can be a Person, that will hold the first and last name of that someone and maybe an address or phone number. Each object can be like a mini java program in that it can have methods (or functions) of its own. However, an object generally needs to be instantiated before you can access the fields or methods of that function. If it is not you will get a runtime error that may kill your program. To check if the object has been instantiated (that is, if it exists) you would call: if(person null) which makes it evaluate the opposite way.

Related questions

Why do you need runtime polymorphismis inheritance necessary for it?

Runtime polymorphism is required because accessing the runtime type of an object is expensive. And yes, inheritance is required for it because polymorphism is enabled through virtual functions. It is not the programmer's responsibility to determine the runtime type of an object because that information should be provided by the object's own virtual table. Thus when you implicitly invoke a virtual method of the base class, you rightly expect most-derived method to be executed, even when you cannot know in advance the exact type of the derivative -- all you know is that it is a type of base class. And that's all you need for polymorphism to work. If you ever find yourself having to turn on the runtime type of an object in order to invoke one of its methods, then you need to seriously consider redesigning your classes. How can your code possibly cope with a runtime type it has no knowledge of, such as a derived object of a class created by a third-party? In those instances you would have no way of knowing what specific methods were available. But with virtual methods there is no need to know. You simply invoke the generic virtual methods of your base class and you automatically get specific behaviour; all your derivatives do whatever they've been implemented to do, whether it is to invoke the base class method explicitly, or provide an override, or indeed both!


Why is object-oriented programming advantageous over other techniques?

advantages of object oriented programming over other techniques 1. Reusability of code 2. Easy to access class properties, methods through object 3. Runtime processing based on input values


What is Reflection in C-sharp?

Reflection is a process, which enables us to get information metadata about object in runtime. That information contains data of the class. Also it can get the names of the methods that are inside the class and constructors of that objec


Can a static function be made virtual?

No. Virtual functions are invoked according to the runtime type of the object. That is; the most-derived override is automatically invoked even when the runtime type of the object cannot be determined at compile time. This is achieved through the object's virtual table. Static methods do not have any object associated with them; they can be invoked even when no object of the type exists. Without an object, there can be no virtual table. Thus static functions cannot be virtual. They are mutually exclusive concepts.


Who invoke main function in java?

The Java Runtime Environment invokes main methods.


How to Outline An Object in Unity Game During Runtime?

To outline an object at runtime in a Unity game, you can follow these steps: Add a Line Renderer component to the object you want to outline. Set the positions of the line points using the SetPositions method of the Line Renderer component. To update the object's outline during runtime, you can modify the positions of the line points as needed. This will allow you to create a visual outline around the object during the game's execution.


How can you force the garbage collector to run?

You can't force it but you call System.gc(), which is a "hint" to the runtime engine that now might be a good time to run the GC. But garbage collection using this method is not guaranteed to be done immediately. there is another way to explicitly call the gc(). this method is also define in Runtime class of package java.lang. But u can not create a direct object of class Runtime like Runtime a = new Runtime(); //wrong For that u have to call the method getRuntime() which is static and it is also define in Runtime class the way to create object is Runtime run; //right run = Runtime.getRuntime(); //right now u can call the gc() through the "run " Object. like run.gc(); //right


What is the difference between static and dynamic programming?

in static programming properties, methods and object have to be declared first, while in dynamic programming they can be created at runtime. This is usually due to the fact that the dynamic programming language is an interpreted language.


How would you know whether the object is runtime?

if it is used when the program is running, it's runtime. all objects are either used when the program is running, or useless and so in theory, all useful (aka objects that you need) objects are runtime


Is there a if exists statement in Java programming?

In java you will be handling objects. An object, for example, can be a Person, that will hold the first and last name of that someone and maybe an address or phone number. Each object can be like a mini java program in that it can have methods (or functions) of its own. However, an object generally needs to be instantiated before you can access the fields or methods of that function. If it is not you will get a runtime error that may kill your program. To check if the object has been instantiated (that is, if it exists) you would call: if(person null) which makes it evaluate the opposite way.


Why run time polymorphism is dynamic and compile time polymorphism is static?

The simple answer is that compile-time polymorphism occurs at compile time while runtime polymorphism occurs at runtime. The actual answer is that compile-time polymorphism results in the compiler generating source code on your behalf while runtime polymorphism relies on function pointers or virtual methods to determine the next instruction at runtime. Compile-time polymorphism therefore applies to template functions and classes since that is the only way the compiler can generate source code on your behalf. To achieve this, the runtime type for the template parameters must be fully-defined at compile time, even if those types have runtime polymorphic characteristics of their own. Runtime polymorphism applies to virtual methods and function pointers, both of which can be used to dynamically alter the execution path of your program. Virtual methods are made possible through virtual tables, which are essentially just arrays of function pointers. Each runtime type that derives from a base class with virtual methods provides its own virtual table, thus the runtime type determines which specific function overrides will be invoked at runtime, even if the runtime type cannot be determined at compile time. In this way you can generalise your code to work with the base type but still get the expected polymorphic behaviour whenever a derived type is passed instead.


Where to use polymorphism?

Polymorphism is used whenever you wish to achieve specific behaviour from a generic object, where the object's actual type may not be known or would be impossible to determine at compile time. By declaring virtual methods in the generic type (the base class), and overriding them in the derived type, you ensure that the derived object does "the right thing" regardless of its actual type, and regardless of whether the method is called directly or indirectly via the base class. With polymorphism, there is no need to determine the actual runtime type of the object, you get that for free simply by calling the appropriate virtual methods.