Late binding? Field vs Property. Self vs Static
<p>This has bothered me for a long time, so I thought I'd go ahead and ask.</p>

<p>If I write</p>

<pre><code>import java.util.*;
import java.lang.*;

class Main
{
    public static void main (String[] args) throws java.lang.Exception
    {
            new Shape();
            new Triangle();
    }

    public static class Shape
    {
            static String name = "shape";

            Shape()
            {
                    printName();
            }

            public void printName()
            {
                    System.out.println( name() );
            }

            public String name()
            {
                    return name;
            }
    }

    public static class Triangle extends Shape
    {
            static String name = "triangle";

            public String name()
            {
                    return name;
            }
    }
}
</code></pre>

<p>then the output is</p>

<pre><code>shape
triangle
</code></pre>

<p>But if I write</p>

<pre><code>import java.util.*;
import java.lang.*;

class Main
{
    public static void main (String[] args) throws java.lang.Exception
    {
            new Shape();
            new Triangle();
    }

    public static class Shape
    {
            static String name = "shape";

            Shape()
            {
                    printName();
            }

            public void printName()
            {
                    System.out.println( name );
            }

    }

    public static class Triangle extends Shape
    {
            static String name = "triangle";
    }
}
</code></pre>

<p>then the output is</p>

<pre><code>shape
shape
</code></pre>

<p>In the first version, I have to copy/paste the same function getName() over and over into every subclass. There's has to be a better way. What do I need to change in the second example?</p>
