My java--class field method

Source: Internet
Author: User

Writing a Java program is basically defining the various classes of objects in the real world abstract it shows that the properties of the object and the behavior of the object in the program class is the property of objects represented by a variable to represent the behavior of the object by using a function to represent a variable in a class in a Java program is called a field. "), a function in a class is called a method

Defining fields and methods in a class

"Example" represents the definition of a class for "person"

Class person{

String name;

int age;

void SayHello () {

System.out.println ("hello! My name is "+name"

}

}

The class header is followed by the start class keyword defined by the keyword class flag class, followed by the name of the class name class for the user-defined class should conform to the Java requirements for naming identifiers.

The class body consists of two parts, the domain and the method. Both the domain and the method are members of the class. Multiple domains and methods can be defined in a class. A class can be represented by a class diagram in a uml diagram.

Person

+name:string

+age:int

+birthdate:date

+getinfo (): string--method

1. Fields

A field is a property of an object, a representation of a state, also known as a domain variable member variable field variable

Type Name Field name

int Age

For field variables, if you do not assign an initial value, the system automatically assigns a default value (the numeric type is 0, and the Boolean type is false, the reference type is null.) String type is a reference type)

2. Methods

A method is a representation of the behavior or function of an object that flags the functions and actions of a class to encapsulate the data of a class and an object in Java, similar to a function or procedure in another language, a program fragment method that is used to accomplish some sort of operation consists of a method header and a method body.

4.1.2 Construction method and object creation

1. Construction method

In a program, it is often necessary to create objects that will invoke the constructor of the object to complete the initialization of the object while creating the object

My java--class field method

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.