1. Creating Objects (Instances)
The New keyword since the class is the template for the object, the new class name (); is the meaning of creating an object. New creates an object one time, creating an object in other words, creating the memory again. New creates several objects on several occasions. For example://This is a student class public classes Student {String name; String address; int age; String sex; void Dushu () {System.out.println ("reading ...");} void Lianxi () {System.out.println ("practicing ...");} Here we new the object of this class of students, and give this object to the variable Stu, in the object of the variables attached to the parameter. Then call the method of this object. public class Test {public static void main (string[] args) {Student stu=new Student (); stu.sex= "male"; Stu.name= "Zhang San"; Stu.add Ress= "Hunan"; stu.age=12; Stu.dushu (); Stu.lianxi (); } }
2. Static members? Instance member?
1. Instance members
An instance member is a new object, so variables and methods are called object members or instance members.
2. Static members
Static members are properties and methods that add static to the class template. A static member has only one copy of memory, even if the object is simply referencing the static member of the class in memory, the object does not create its own registry memory to store but to reference. So static member object instances of the properties and methods that have the static keyword are not going to register memory but simply refer back to the static members of the class. Only instance member objects without static will go to register memory themselves. So static members can be accessed directly from the class name without the new object. Because this class is loaded, it already has a static member. For example:
Static members can be accessed directly without the new object.
3. Reference delivery
Since a static member is a shared copy of all instances. and instance members are "learning Java, to the Kaige123.com school" each have their own share. Then there is the relationship of reference passing.
1. Static members will change all instances as long as one instance modifies it. 2. Instance members that's the one you're modifying yourself to have no effect on other instances.
-java Basics-Objects