站点图标

Android Development 03 Challenge 3

参考视频:Android Development for Beginners - Full Course

  本篇内容主要为Java OOP。

public class Organ
{
/* Member */
    private String m_name;

/* Function */
    public Organ(String p_name)
    {
        this.m_name = p_name;
    }

    public String getName()
    {
        return this.m_name;
    }
}

public class Eyes extends Organ
{
/* Member */
    private String m_color;

/* Function */
    public Eyes (String p_name, String p_color)
    {
        super(p_name);
        this.m_color = p_color;
    }

    public String getColor()
    {
        return this.m_color;
    }
}

public class Heart extends Organ
{
/* Member */
    private int m_HR;

/* Function */
    public Heart(String p_name, int p_HR)
    {
        super(p_name);
        this.m_HR = p_HR;
    }

    public int getHR()
    {
        return this.m_HR;
    }
}

public class Human
{
/* Member */
    String m_name;
    Heart m_heart;
    Eyes m_eyes;

/* Function */

    Human(String p_name, Heart p_heart, Eyes p_eyes)
    {
        this.m_name = p_name;
        this.m_heart = p_heart;
        this.m_eyes = p_eyes;
    }

    public void PrintInfo()
    {
        System.out.println("This is: " + this.m_name + ", who's eye's color is: " + this.m_eyes.getColor() + ", and HR is: " + this.m_heart.getHR());
    }
}

public class Main
{
    public static void main(String[] args)
    {
        Human ZS = new Human("ZS", new Heart("Heart", 60), new Eyes("Eyes", "Black"));

        ZS.PrintInfo();
    }
}
退出移动版