Computer Science 225
Advanced Programming

Spring 2017, Siena College

Hidden BlueJ Project

Click here to download a BlueJ project for Hidden.


Hidden Source Code

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


Hidden.java

/*
 * Example Hidden: Example demonstrating hiding
 *
 * Based on example from Darren Lim, Siena College, Computer Science 225
 */

public class Hidden {
    public static void main(String[] args)
    {
        Animal x = new Tiger();

        // Access news
        System.out.println("(1) x.news is " + x.news);
        System.out.println("(2) ((Tiger)x).news is " + ((Tiger)x).news);

        //Invoke static method smile
        System.out.println("(3) x.smile() is " + x.smile());
        System.out.println("(4) ((Tiger)x).smile() is " + ((Tiger)x).smile());

        //Invoke instance methods getNews() and getMessage()
        System.out.println("(5) x.getNews() is " + x.getNews());
        System.out.println("(6) x.getMessage() is " + x.getMessage());

    }
}

Animal.java


/**
 * Animal class for Hidden example
 */
public class Animal
{
    public String news = "Animal's news";
    public String message = "Animal's message";

    public static String smile() 
    {
        return "smile from Animal";
    }

    public String getNews()
    {
        return news;
    }

    public String getMessage()
    {
        return message;
    }
}

Tiger.java


/**
 * Tiger class for Hidden example
 */
public class Tiger extends Animal
{
    public String news = "Tiger's news";
    public String message = "Tiger's message";

    public static String smile()
    {
        return "smile from Tiger";
    }

    public String getNews()
    {
        return news;
    }
}