Tuesday, July 6, 2010

Exercise: Human class

Use only Notepad

Write a new class Human with

• two public variables

  – int age

  – string name

• two constructors

  – Default constructor (set age=0 and name =“”)

  – Constructor to take in two parameters to set age and name

Answer:

class Human
{
    public int age;
    public string name;
    public Human()
    {
        age = 0;
        name = "";
    }
    public Human(int a, string n)
    {
        age = a;
        name = n;
    }
}

0 comments:

Post a Comment