e martë, 15 janar 2008

Question on hiding instance variable

Consider the class below

class joel
{
public int num = 0;
public void displaynum()
{
int num = 1;
}
public void displaynextnum()
{
num = 2;
}
}

What will below codes print and why?

1. joel j = new joel();
j.displaynum();
Console.WriteLine("Display member " + j.num);
Console.ReadKey();

2. joel j = new joel();
j.displaynextnum();
Console.WriteLine("Display member " + j.num);
Console.ReadKey();

Nuk ka komente: