Classes and objects

Source: Internet
Author: User

JAVA is an object-oriented programming language, class is an important object-oriented content, you can use a class as a custom type, you can make a class to define variables, this type of variable is referred to as reference variables. This means that all classes are reference variables.

Object-oriented has two important concepts: Class and Object (object, also known as an instance), where the class is an abstraction of a batch of objects, and the object is a concrete entity

The Java language is an object-oriented program of the actual language, classes and objects of the object-oriented core, the definition of a class contains three most common members: constructors, member variables and methods, member variables are used to define the class or the class's instance contains state data, Method defines the behavior characteristics or functionality implementation of the class or instance.

The constructor is used to construct an instance of the class, and JAVA invokes the constructor with the new keyword to return an instance of the class.

Static is a special keyword that can be used to modify members such as methods, member variables, and so on. The member of the static modifier indicates that it belongs to the class itself, not to a single instance of the class, because the static decorated member variables and methods are also called methods of the class's variables or classes, not the normal method of static decoration, the member variable

belongs to a single instance of the class, not to that class. Therefore, member variables and methods that do not use static modifiers are often referred to as instance variable instances and methods. (The real function of static is to differentiate between member variables, methods, inner classes, initialization blocks, four of which belong to the class itself or to an instance.) A member defined in a class, static equivalent to a flag)

The constructor can neither define a return value type nor use void to declare that the constructor has no return value (if a return type is defined for the constructor or a void declaration constructor does not return a value it will no longer be a constructor)

1.JAVA Grammar rules. In fact, the constructor of a class has a return value, and when the constructor is called with the New keyword, the constructor returns an instance of the class, which can be used as the constructor's return value. Therefore, the constructor returns a value type that is always the current class without defining a return value type. However, it is important to note that you should not explicitly use return in the constructor to return the object of the current class because the constructor's return value is implicit.

The generation and use of objects

The fundamental way to create an object is the constructor, which invokes the constructor of a class with the new keyword to create an instance of the class (if permissions allow classes to define methods and member variables, they can be called through the class.) A class or instance accesses a method or member variable, and an access statement is a class. Variable name for Class | method)

Classes and objects

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.