Reputation:
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
}
}
}
Upvotes: -1
Views: 69
Reputation: 28509
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.
Upvotes: 1