✅ static r public?
I was writing code something like this,
class Physics
{
public int Force;
}
and I was trying to access the Force variable I have, but it said I needed the variable to be static. Why was it asking me this when I already have public down?
2 Replies
because you have to actually create
Physics
with
var myPhysics = new Physics();
just defining it doesn't put it in existence
also because in that way you could not have more than one instance of itNon-static variables are only accessible from an instance of the class