2015-3-29 Java class, object definition and usage

Source: Internet
Author: User

1, what is a class?

A: The class is an objective, abstract, conceptual thing.

2, what is an object?

A: The object is concrete, practical, representing a thing. For example: A car is a class, a car, a bicycle is his object.

About classes and objects: A class is a template for an object that is an individual of the class.


How do I define a class in 3,java?

Class name defines human in Java syntax: public class person{}

4, how is the object defined?

1, Object declaration: Class name Object name; 2, object creation Object name = new class name (); new function: allocates memory space.
Can also be written as: Class Name Object name = new class name ();

5, Example: Create an air conditioner and call the refrigeration.

Design an air-conditioning package Practice;public class Kongtiao {    ///Air Conditioning property    String name;    String Pinpai;    String Pishu;    int tempeture;        Define refrigeration behavior    void Cool ()    {        tempeture--;    }        Define heating behavior    void hot ()    {        tempeture+=7;    }    Main function public    static void Main (string[] args) {        Kongtiao kt = new Kongtiao ();        Kt.name = "air conditioning";        Kt.pishu = "2 Horses";        Kt.tempeture =;        Kt.pinpai = "Gree";        /**        Kt.cool ();        System.out.println ("The temperature of the air conditioning is" +kt.tempeture);        *                /Kt.hot ();        System.out.println ("The temperature of the air conditioner is" +kt.tempeture);}                    }

2015-3-29 Java class, object definition and usage

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.