answersLogoWhite

0

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

12y ago

What else can I help you with?

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 can I transfer inheritance money to my bank account?

To transfer inheritance money to your bank account, you will need to provide the necessary documentation, such as a copy of the will or death certificate, to the executor of the estate or the financial institution handling the inheritance. They will then facilitate the transfer of the funds to your designated bank account.


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.


Do you need playready PC runtime x86 on your windows 7 PC?

If you are using software or applications that require PlayReady DRM (Digital Rights Management) for content playback on your Windows 7 PC, then you will need the PlayReady PC Runtime x86 installed. This component is essential for the proper functioning of protected media content. However, if you are not engaging with such content, it is not necessary to have it installed. Always ensure your system meets the requirements of the applications you intend to use.


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


Why does DNA replication need to occur for cell division and genetic inheritance?

DNA replication is necessary for cell division and genetic inheritance because it ensures that each new cell receives an exact copy of the genetic information stored in the original cell's DNA. This process is crucial for maintaining genetic stability and passing on traits to offspring.


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.