Hi all
I am trying to learn c#, at the moment i am stuck on an inheritance and set get example
here is my code
Main program
[code=c#]
static void Main()
{
squar sq = new squar();
sq.squareArea() ;
Console.WriteLi ne("The area of a square is " + Area);
Console.Read();
}
[/code]
and here is my parent and child class
[code=c#]
using System;
namespace simpleInheritan ce
{
public class shapes
{
private int h;
public int height
{
get{ return h;}
set{h=10;}//<--here
}
}
public int getHeight()
{
int theHeight = height;
return theHeight;
}
}//end class shapes
public class squar : shapes
{
public void squareArea()
{
int side = getHeight();
int area = side * side;
Console.WriteLi ne("area is " + area);
}
}
}
[/code]
my question is why doesnt my set method in the shapes class (parent) get executed... only the get method is being executed...
thanks in adavance
I am trying to learn c#, at the moment i am stuck on an inheritance and set get example
here is my code
Main program
[code=c#]
static void Main()
{
squar sq = new squar();
sq.squareArea() ;
Console.WriteLi ne("The area of a square is " + Area);
Console.Read();
}
[/code]
and here is my parent and child class
[code=c#]
using System;
namespace simpleInheritan ce
{
public class shapes
{
private int h;
public int height
{
get{ return h;}
set{h=10;}//<--here
}
}
public int getHeight()
{
int theHeight = height;
return theHeight;
}
}//end class shapes
public class squar : shapes
{
public void squareArea()
{
int side = getHeight();
int area = side * side;
Console.WriteLi ne("area is " + area);
}
}
}
[/code]
my question is why doesnt my set method in the shapes class (parent) get executed... only the get method is being executed...
thanks in adavance
Comment