Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

using System;

namespace FirstConsoleProject
{

class MainClass
{
//interface describes what should be in a class and class implements
each method
//name interface with "I" for clarity
interface IItem
{
//don need public or private here
//put get set for a property
string name {get;set;}
int goldValue {get;set;}
//dont need implement methods here
void Equip();
void Sell();
}

//Sword class inherits from IITem, class can inherit from multiple
interfaces
//but cannot inherit from multiple classes!

//Methods Equip and Sell must be implemented in Sword class


//Properties name and goldValue must be implemented in Sword class
class Sword : IItem
{
//implement derived properties
public string name {get;set;}
public int goldValue {get;set;}

//class constructor below


public Sword(string _name)
{
name=_name;
goldValue=100;
}
//implement derived methods
public void Equip()
{
Console.WriteLine(name +" equipped");
}

public void Sell()


{
Console.WriteLine(name +" sold for "+goldValue+" imaginary
dollars!");
}
}

public static void Main(string[] args)


{
//create new sword
Sword sword = new Sword("Sword of destiny");
sword.Equip();
sword.Sell();
Console.ReadKey();
}
}
}

You might also like