- If a there is a static field declared in a non static context (class) it can be accessed without creating an object (object of the class).
{
public static double salesTaxPercentage = 20;
}
Sales.salesTaxPercentage = 35; // can access like this
- You cannot access static fields from an instance of the type it belongs to.
_sales.salesTaxPercentage = 35; // Compile error.
- If you declare a Class as static it cannot contain non static members such as fields, methods, and constructors.
public void Sales2() {...} // Compile Error
}
- A non static context cannot be accessed within a static context.
public int a = 0;
static class Sales {
static class Sales {
a = 10; // Compile Error
}
This comment has been removed by a blog administrator.
ReplyDelete