Maha

Maha

  • NA
  • 0
  • 326.1k

Static

Jun 24 2013 6:50 PM
Following one is a simple program. I inserted static key word to the object class variable idNumber. Program is compiling fine, but I expected an error message. Please explain me what is the reason for its compilation with or without key word static.

using System;
public class CreateEmployee
{
public static void Main()
{
Employee myAssistant = new Employee();

myAssistant.SetId(345); //Instance Method

Console.WriteLine("ID # is {0}", myAssistant.GetId());

Console.ReadKey();
}
}
internal class Employee
{
private static int idNumber;

public int GetId()
{
return idNumber;
}
public void SetId(int id)
{
idNumber = id;
}
}
//ID # is 345


Answers (6)