answersLogoWhite

0


Best Answer

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!

User Avatar

Wiki User

10y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why do you need runtime polymorphismis inheritance necessary for it?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Should you install Java EE on a client?

No, for the client you only need the runtime, i.e., the JVM.


Why you neet interface in java?

When you need the benefits of multiple inheritance while avoiding the DDD (Deadly Diamond of Death). Java doesn't allow multiple inheritance anyway.


How do you get java on to your computer?

You download it from the Java site - www.java.com. To be precise, there are different downloads; for the end user, all you need is the Java runtime. For developers who want to write Java programs, you'll probably want to work with an IDE. There are several options for an IDE, including Eclipse, Netbeans, and others. The IDE includes the required runtime.


When to use inheritance in c plus plus?

You use inheritance whenever you need a more specialised version of an existing class (the base class). Rather than creating a new class entirely from scratch, and therefore duplicating tried and tested code, you simply build upon the existing class, overriding the existing methods and adding more specialised methods, whilst retaining all the generic functionality of the base class.


Why is multiple inheritance implemened through interfaces?

Interfaces have only methods declared and not defined. So that these various methods can be altered or customized or written according to the need. Hence Multiple inheritance is implemented through Interfaces.Interface is a progam which just declares various methods or functions, so that any user can write the contents of that method declaration.AnswerTrue Multiple Inheritance refers to the ability to inherit from multiple CLASSES. Thus, a true multiple inheritance language does not use interfaces. However, many single-inheritance languages provide most of the benefits of the multiple inheritance concept by using interfaces (Java, for example). The problem with true Multiple Inheritance is twofold:(a) at the compiler and runtime level, it is often difficult to determine which method is being referred to, as M.I. can lead to very convoluted (and sometimes conflicting) namespaces(b) there is no specific superclass, which can lead to problems with determining relationships between classesUsing a S.I. model with interfaces avoids these two problems.

Related questions

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


Do you pay taxes on a trust inheritance?

Depending on where someone lives depends on the need to pay taxes on any inheritance they get from a living trust. The beneficiary of an estate from inheritance will need to pay taxes to take possession of assets.


Does an inheritance after a person's death need to be part of the estate?

Once someone has died, they can longer receive an inheritance.


Should you install Java EE on a client?

No, for the client you only need the runtime, i.e., the JVM.


What is java's purpose on my PC?

Programs that are specifically designed with Java require a Java runtime to work on a computer. (In the case of Java, the runtime is called "Java Virtual Machine".) If you have any such program, you need to have Java.


Which languages necessarily need heap allocation in the runtime environment?

Those that allow dynamic data structure


How do you go about claiming your inheritance from your grandmother?

In order to go about claiming your inheritance from your grandmother, you will need to file a document in the court stating your entitlement to the inheritance. The claim must be endorsed by the court and sent to the administrator of the estate.


If I need the money for medical bills, is it possible to get a probate cash advance on my inheritance?

For Heirs of a Probate who need advance cash on their Inheritance now, rather than waiting for the Estate in Probate to close, Heir Advance Company offers you an immediate Probate Loan, or Inheritance cash advance solution.


You are receiving some inheritance money from your mother who lived in New Zealand Do you have to pay taxes on it here in Texas?

You would not pay U.S. income tax on the inheritance, but generally do need to report the inheritance to the IRS on Form 3520.


How can get rid of A Runtime Error has occured do you wish to debug?

How do I get rid of a runtime erroe has occured. Do you wish to debug??? There are 3 step to repair runtime error If you got runtime error then there is a 94% chance that your computer has registry problems. To repair runtime error you need to follow the steps below: * Step 1 - Download a Perfect Optimizer,install this error repair tool. * Step 2 - Click the Repair All Button.It will scan you PC for Free. * Step 3 - Then click the Repair All Button again and your done! It is very easy to repair runtime error. Here are the URL of Perfect Optimizer: http://www.errorremovers.com/tidporp-runtime_error-zz0005


How do a UK citizen get a tax code to get my inheritance from an uncle in US?

You don't need a UK tax code to receive overseas inheritance. The only time you need a UK tax code - is if you're liable to pay tax.


Why you neet interface in java?

When you need the benefits of multiple inheritance while avoiding the DDD (Deadly Diamond of Death). Java doesn't allow multiple inheritance anyway.