April 29th, 2008, 01:17 PM
|
#2
|
|
Super F@D Folder
Join Date: Jun 2004
Posts: 5,083
|
Static attributes/methods are methods of the class as opposed to the object.
Suppose you have a class called "MyClass" with the static attributes "myStatic1" and "myStatic2" and two nonstatic attributes "myRegular1" and "myRegular2"
Code:
public class MyClass
{
static int myStatic1, myStatic2;
int myRegular1, myRegular2;
}
now you create an object of type MyClass
Code:
public static void main()
{
MyClass myObject = new MyClass();
MyClass.myStatic1; //valid statement
MyClass.myRegular1; //invalid statement
myObject.myStatic1; //invalide statement
myObject.myRegular1; //valid statement
}
you notice main is a static method....it's a method that's run without ever having an object created!
Last edited by sr71000 : April 29th, 2008 at 01:20 PM.
|
|
|