Implement the "TransformToElephant" method so that the program displays the line "Elephant" in Console

64 Views Asked by At

The program displays the string "Fly" on the screen, and then continues to execute the rest of the code. Implement the TransformToElephant method so that the program displays the line "Elephant", and then continues to execute the rest of the code without first displaying the line "Fly".

using System;

namespace ConsoleAppTransformToElephant
{
    internal class Program
    {
        static void Main(string[] args)
        {
            TransformToElephant();
            Console.WriteLine("Fly");
            //... custom application code
        }

        static void TransformToElephant()
        {
            //... write your code here 
        }
    }
}
1

There are 1 best solutions below

0
NineBerry On

This is a classic job interview question. And it is a trap. In my opinion the only correct answer is to explain why the given code doesn't follow good coding style and that the requested change would make it even worse.

Relevant ideas are that methods should not have side-effects and that oop languages have specific mechanisms to implement polymorphism.