Rajendra Sharma

Rajendra Sharma

  • 1.3k
  • 399
  • 2.1k

How to assign value same variable name in base class and derived class

May 31 2023 11:29 AM
public   class clsb
{
    public string subjectName = "";
    public string mainsubject()
    {
       return subjectName;

    }
}

public  class clsA : clsb
{
    public string subjectName = "";
    public string Allsubject()
    {
            return subjectName;
    }
}

private void getdata()
{
    clsA obj = new clsA();
    //base and derived class 
    obj.subjectName = "English";
    string A1 = obj.mainsubject();
    string A2 = obj.Allsubject();
}

 


Answers (2)