Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class program1
- {
- public void main(String[] args)
- {
- Abc.method();
- Abc.i = 12;
- }
- }
- class Abc
- {
- /*A static member belongs to the class and not a specific instance/object.*/
- //a static variable is shared among all the objects/instances of a class.
- //If I don't want to instantiate/create an object for a class I can just use static and just have to type the class name.
- //You can't have a non static variable in a static method.
- static int i; //Static tells the program that you only need class name to call.
- public static void method() //static tells the program that you don't need an object to call the method from the class only class name
- {
- System.out.println("Hello World!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement