Computer Science 225
Advanced Programming

Spring 2017, Siena College

PrivateInheritance BlueJ Project

Click here to download a BlueJ project for PrivateInheritance.


PrivateInheritance Source Code

The Java source code for PrivateInheritance is below. Click on a file name to download it.


PrivateInheritance.java

/*
 * Example PrivateInheritance: "accessing" private methods?
 *
 * Based on example by Darren Lim, CSIS 225, Siena College
 *
 */
public class PrivateInheritance
{
    private final String name;

    // try different access controls here: it matters
    private void prname()
    {
        System.out.println(name);
    }

    PrivateInheritance(String name)
    {
        this.name = name;
    }

    public static void main(String[] args)
    {
        new PrivateInheritance("main").doit();
    }

    private void doit()
    {
        new PrivateInheritance("doit")
        {
            void method()
            {
                prname();
            }
        }.method();
    }
}