0

I am teaching someone the basics of Java. I am trying to give him a good definition of static without using 'instance'. My definition so far has been:

static: A keyword that declares that there is only one instance of it.

Any better way to define static without having to go into objects ?

Colin Koenig
  • 65
  • 1
  • 3
  • 15
  • Docs are always pretty good at explaining things : http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html – Rahul Mar 08 '14 at 06:03

2 Answers2

1

I think it's important you go into objects. Then you can just say that static variables are attached to the class, and they are shared across all instances of the same class.

EDIT:

As for learning objects, I recommend BlueJ. It's an easy way to visualize what instances are in terms of the blueprints (classes).

user2793390
  • 741
  • 7
  • 29
0

Static methods and fields are owned by the class. They can be accessed from within the class by referring to the identifier and outside the class, if public, by ClassName.staticFieldName or ClassName.staticMethodName(...).

user3352495
  • 374
  • 3
  • 11
  • How do you think I should approach someone without understanding with computers and get into Objects, hmm. This is a hard one :P. Any tips? – Colin Koenig Mar 08 '14 at 06:07
  • I didn't mention "object", but only "class". More broadly, static things are typically initialized only once the first time and stay in computer memory until the program finishes execution. – user3352495 Mar 08 '14 at 06:20