Class and object, method, object, Method

Source: Internet
Author: User

Class and object, method, object, Method

Class: A class is an abstract concept. It contains data (usually expressed by nouns) and data manipulation (usually represented by verbs ). For example, a person is an abstract concept. A person has data such as name, age, and height, as well as data manipulation such as eating and running.

Class: the content of a class. The class consists of two parts:
A) data. Data is called a Property or Attribute in a class or a Member variable ).
B) data manipulation. Such manipulation is called a method in a class)

Object: an object is a specific concept and a specific expression of a class. For example, a person is a class, while a person, such as Michael Jacob, Mr. Li, and Mr. Wang, is an object.

Method: The method definition cannot be nested, so you cannot define another method in a method. Methods can only be defined in classes.

 

Definition class

Modifier class Name
{
// Class content (including attributes and methods)
}


Definition Method

Modifier return type method name ([parameter 1, parameter 2, parameter 3…])
{
// Method body
}

Create object
Class {
// Class content (including attributes and Methods
}
A a = new ();

Define attributes
Public class Person
{
Modifier type attribute name;
}

 

Naming Conventions

A) Class: the first letter is capitalized. If a class name consists of multiple words, the first letter of each word is capitalized, and no connector is used in the middle. For example, the Person class and the MemberTest class.
B) method: lowercase letters. If a method is composed of multiple words, all the letters of the first word are in lower case, starting from the second word, and the first letter of each word is in upper case. For example, add or addThreeInt.
C) attributes: The naming conventions and methods are the same. For example, age, ageOfPerson.

The connection and difference between member variables and local variables:

A) whether it is a member variable or a local variable, it must be declared (defined) before use ).
B) for local variables, they must be initialized before use. For member variables, they can be not initialized before use. If you do not initialize a member variable, each type of member variable has a default initial value.
The initial values of the I. byte, short, int, and long types are 0.
Ii. The initial values of float and double types are 0.0.
Iii. Initial Value of the char type '\ u000000'
The initial value of the iv. boolean type is false.

Reference type: The reference type is used on objects. An object can be pointed to by multiple references, but at the same time, each reference can only point to a unique object. If an object is pointed to by multiple references, any reference that modifies the attributes of the object will be reflected in other references.

 

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.