C# vscode practice - inheritance

in kr-it •  6 years ago 

For the Inheritance, We have to be careful to use variables.

We have upper class of Address
@ street
@ city
@ zip

and InternationalAddress inherited Address
@ country

Then, we can not put country to address directly

I wanted to put @address.Country = "Korea";
But it returns the compile error.

Then i changed to @interaddress.Country = "Korea";
It has succeeded.

Here is the code

/////////////////////////

public class Address
{
public string StreetAddress;
public string City;
public string State;
public string Zip;

    public override string ToString()
    {
        return string.Format("{0}" + Environment.NewLine +
            "{1}, {2} {3}",
            StreetAddress, City, State, Zip);
    }
} 

public class InternationalAddress : Address
{
    public string Country;

    public override string ToString()
    {
        return base.ToString() + Environment.NewLine + Country;
    }
}

//////////////////////////////

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!