inheritance problem

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
 
P

Peter Duniho

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
 
S

sahel

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 .
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Is it based up polymorphy or just inheritance? 2
creating a file 7
what is base() in inheritance 2
small problem 5
error :( 4
? 7
static 2
Use of event handling 6

Top