This is Sparta, or is it?

Viewed 9627

The following is an interview question. I came up with a solution, but I'm not sure why it works.


Question:

Without modifying the Sparta class, write some code that makes MakeItReturnFalse return false.

public class Sparta : Place
{
    public bool MakeItReturnFalse()
    {
        return this is Sparta;
    }
}

My solution: (SPOILER)

public class Place
{
public interface Sparta { }
}

But why does Sparta in MakeItReturnFalse() refer to {namespace}.Place.Sparta instead of {namespace}.Sparta?

3 Answers
Related