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 : Define Thread Thread : It is a

    Thread: It is a lightweight procedure which is managed by the Java Virtual Machine (abbreviated as JVM). Support for threads is given by the Thread class in java.lang package.

  • Q : How is an XPointer processor configured

    How is an XPointer processor configured?

  • Q : Explain Exclusive-or operator

    Exclusive-or operator: An exclusive-or operator (^) is both a Boolean operator and the bit manipulation operator. The Boolean version provides the value true when only one of its operands is true; or else it offers the value false. Likewise, the bit m

  • Q : Uses of BYTE Write a program that shows

    Write a program that shows the uses of BYTE, WORD and DWORD?

  • Q : Explain Timesharing system Timesharing

    Timesharing system: It is an operating system which shares processor time among multiple processes by assigning each a time slice. Once a process's time slice has finished or expired, the other procedure is given a possibility to run.

  • Q : Explain Conditional operator

    Conditional operator: It is an operator taking three operands that is, a ternary operator. The conditional operator (?:) is employed in the form bexpr ? expr1 : expr2

    Q : Define Final variable Final variable :

    Final variable: A variable with final reserved word in its declaration. The final might not assigned to once it has been initialized. Initialization frequently occurs as a part of its declaration. Though, the initialization of an uninitialized final f

  • Q : Explain Copy constructor Copy

    Copy constructor: It is a constructor which takes a single argument of similar class. For illustration:     public class Point {        

  • Q : Define the term Stack trace Define the

    Define the term Stack trace: It is a display of the runtime stack.

  • Q : Print the factors of each perfect number

    An integer number is said to be a perfect number if its factors, including 1 (but not the number itself), sum to be the number. For example, 6 is a perfect number because 6 = 1+ 2+ 3. Write a function perfect that determines if parameter number is a perfect number. Us

©TutorsGlobe All rights reserved 2022-2023.