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 the term Scheduler Define the

    Define the term Scheduler: The portion of the Java Virtual Machine (abbreviated as JVM) which is responsible for managing the threads.

  • Q : Updating the Status of an Order in SQL

    Build a procedure named STATUS_SHIP_SP which permits a company to employee in the Shipping Department to update the status of an order to add up shipping information. The BB_BASKETSTATUS table maintains a list of events for each order and hence a shopper can see the c

  • Q : Explain Primitive Type Abstractions

    Primitive Type Abstractions: An effective way to reduce the state space of a program is to replace the primitive types with the corresponding abstractions that encapsulate all the possible operations that are performed on these types.

    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 : What is an Instance variable Instance

    Instance variable: It is a non-static field of a class. Each and every individual object of a class has its own copy of this field. This is in contrary to a class variable that is shared by all instances of class. Instance variables are employed to mo

  • Q : Differentiate overriding and

    Differentiate overriding and overloading method?

  • Q : Define Constant Constant : It is the

    Constant: It is the memory block where value can be stored once although can’t modify later on throughout program execution. Example: const int pi =3.14;

  • Q : Define the term Local inner class and

    Define the term Local inner class and Local variable: Local inner class: It is an inner class stated in a method. Local variable: It is a variable defined within

  • Q : Explain Imperative programming

    Imperative programming: The style of programming generally related with languages such as FORTRAN, C, Pascal and so forth. Imperative programming is differentiated from functional programming in that the previous is strongly tied to the idea of variab

  • Q : Define Context Normal 0 false false

    Normal 0 false false

©TutorsGlobe All rights reserved 2022-2023.