Object-Oriented Learning Java Tutorials (iii)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.