--%>

Use Polymorphism

Use Polymorphism: Programs, especially those converted from non-OOP languages like C, sometimes use state where they should use inheritance. For example,

1225_polymorphism1.jpg

The variable type is used to explicitly store the type of an instance of class A or B. It is initialized in the constructors of both classes and is used in the A::foo() method to determine the exact type of the object so that the appropriate operations are carried out. Besides being error prone (type initialization, branch completeness) and breaking fundamental object-oriented abstraction rules (base classes should not have to know about their concrete derived classes), this produces more code (the branches) and more data (type fields) that have to be handled by the model checker. You can use the inheritance mechanism in C++ to do this more elegantly, as shown below:

856_polymorphism2.jpg

   Related Questions in Programming Languages

  • Q : Explain the way to handle the mapping

    Explain the way to handle the mapping form.

  • Q : What is XLink What is XLink? Answer: It

    What is XLink? Answer: It is a part of the XLL specification which is concerned along with specifying links among documents.

  • Q : What is Pointer Arithmetic Pointer

    Pointer Arithmetic: C and C++ provide the ability to modify a pointer’s target address with arithmetic operations. This is used, for example, to index arrays. MyObject* P = ...

    Q : Give some instances of XML DTDs or

    Give some instances of XML DTDs or schemas which you have worked with?

  • Q : What is Actual argument Actual argument

    Actual argument: The value of an argument enacted to a method from exterior to the method. Whenever a method is called, the real argument values are copied into analogous formal arguments. The kinds of the actual arguments should be compatible with th

  • Q : State the term Win32 State the term

    State the term Win32. Answer: Win32 considers to Microsoft 32 bit Windows API. Applications of Win32 are programs that are built along with the Win32 API.

  • Q : Define Unions Unions: Unions in C and

    Unions: Unions in C and C++ are object overlays—aggregate quantities such as structs, except that each element of the union consists offset 0, and the total size of union is only as large as is required to hold its largest member (Kernighan and

  • Q : Define Daemon thread Daemon thread :

    Daemon thread: The daemon threads are non-user threads. They are usually employed to carry out low-priority tasks which must not take priority over the major task of the program. They can be employed to do helpful work whenever all other user threads

  • Q : State the term GPO links State the term

    State the term GPO links? Explain.

  • Q : Explain State State : The objects are

    State: The objects are said to possess state. The present state of an object is symbolized by the joint values of its attributes. Protecting the state of an object from unsuitable inspection or modification is a significant aspect of class design and