Learn to program the Java tutorial Object-oriented publishing, welcome to visit through the xuebiancheng8.com
The above two analyses of classes and objects, and how to define objects. The following is an analysis of how objects are used
The following defines a class first
The public class car{//defines the first letter of the class list to be capitalized, and at the same time see knowingly
String name; Attribute names are defined
int price; Define the price
public void Run () {//defines the Run method
System.out.println ("The car is running");
}
public void Stop () {//defines the Stop method
System.out.println ("The car Stopped");
}
}
The class is defined so that the object can be produced by the class
The specific code is as follows:
Car audi = new car ();//define the Audi object, which produces a car by car class
Audi.name= "Audi"; The name of the car is Audi.
The price of the audi.price=400000;//car is 400000.
Audi.run (); Audi and start running
Audi.stop ();//audi, the car's stopped.
The above is how the object is generated by the class, and the run and stop methods of the calling object
For more information, please login to xuebiancheng8.com to access
The specific URL is
Http://xuebiancheng8.com/play/goodgoodstudy_85_daydayup.html
Object-Oriented Learning Java Tutorials (iii)