On the definition of classes and objects in Java programming _java

Source: Internet
Author: User

1, what is a class?

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

2, what's the object?

A: The object is concrete, practical, and represents a thing. For example: A car is a class, a car, a bike is his object.

A description of classes and objects: A class is a template for an object and an object is an individual of a class.

How do you define a class in 3,java?

Class class name
defined in Java syntax Human: public
class person
{
}

4. How do I define an object?

1, Object declaration: Class name Object name;

2, object creation Object name = new class name (); new function: Allocate memory space.

It can also be written as follows: Class Name Object name = new class name ();

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

Design an air-conditioning
package practice;

public class Kongtiao {
  //Air conditioner 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 = "Beautiful";
    Kt.pishu = "2 Horses";
    Kt.tempeture =;
    Kt.pinpai = "Zhi Gao";
    /**
    Kt.cool ();
    System.out.println ("The temperature of the air-conditioner is" +kt.tempeture);
    * *
    
    kt.hot ();
    System.out.println ("The temperature of the air-conditioner is" +kt.tempeture);
    
    
  }

The above analysis of Java programming class and object definition is small to share all the content of everyone, hope to give you a reference, but also hope that we support cloud habitat community.

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.