inheritance problem

  • Thread starter Thread starter sahel
  • Start date Start date
S

sahel

Hi I wrote this program but it has error plz help me to solve it

Errore:

Error 1 An object reference is required for the non-static field,
method, or property
using System;
namespace ConsoleApplication85
{
class Program
{
static void Main(string[] args)
{
}
class f
{
protected int d = 10;
}
class g:f
{
static public void tabe()
{
Console.WriteLine(d);
}
}
}
}

and i don't really know what is the usage of inheritance
 
sahel said:
[...]
Error 1 An object reference is required for the non-static field,
method, or property
[...]
class f
{
protected int d = 10;
}
class g:f
{
static public void tabe()
{
Console.WriteLine(d);
}
}
[...]
and i don't really know what is the usage of inheritance

You don't have an inheritance problem. You have a static problem.

You either need to make "d" static, or remove "static" from "tabe".

And while in this case, it's easy enough to see the problem in your
code, you really should get in the habit of providing more detailed
information.

It's good that you posted the complete error text, but you should also
indicate exactly where in your code is the line and column that the
error occurs (and note that the exact numbers aren't useful to us…you
need to look at the numbers, and then identify that location in the code
some other way).

Pete
 
sahel said:
[...]
Error      1       An object reference is required for the non-static field,
method, or property
[...]
        class f
        {
            protected int d = 10;
        }
        class g:f
        {
            static public void tabe()
            {
                Console.WriteLine(d);
            }
        }
[...]
and i don't really know what is the usage of inheritance

You don't have an inheritance problem.  You have a static problem.

You either need to make "d" static, or remove "static" from "tabe".

And while in this case, it's easy enough to see the problem in your
code, you really should get in the habit of providing more detailed
information.

It's good that you posted the complete error text, but you should also
indicate exactly where in your code is the line and column that the
error occurs (and note that the exact numbers aren't useful to us you
need to look at the numbers, and then identify that location in the code
some other way).

Pete

thanks;
it solve with your help .
 
Back
Top