Question related to static

Good morning!

i would like to ask you sthg related to static variables :

package1;

import java.io.*;

public class hello {

int n;

static int k;

public hello1() {

n++;

}

public hello2() {

k++;

}

}

What抯 the difference between the package variable n and the static variable k?

Also,What's the difference between static and non-static methods/classes?

Thanks,in advance!

[470 byte] By [g_p_javaa] at [2007-10-2 5:33:17]
# 1

Static methods and variables belong to a class whereas non-static elements belong to an object, an instance of a class.

So if you modify a static variable of an object, all others objects of the same class will have the same static variable value

You could call a static method without having an instance of object

antoine.lemoinea at 2007-7-16 1:44:06 > top of Java-index,Java Essentials,New To Java...