Classes and objects, methods

Source: Internet
Author: User

Class: A class is an abstract concept in which a class contains data (usually represented by nouns) and manipulation of the data (usually expressed using verbs). For example, a person is an abstract concept, people have names, age, height and other data, as well as eating, running and other manipulation of data.

Class: What the class contains, the class contains two parts altogether:
A) data, which is called an attribute (property or attribute) or a member variable (Member variable) in a class.
b) Manipulation of data, which is called a method in a class

Object: An object is a concrete concept that is a concrete representation of a class. For example, a person is a class, and Zhang San, John Doe, Harry and other specific people is the object.

Method: The method definition cannot be nested, and it is said that another method cannot be defined in one method. Method can only be defined in a class.

Defining classes

The name of the Modifier class class
{
The contents of the class (including properties and methods)
}


Defining methods

Modifier returns the type method name ([parameter 1, Parameter 2, Parameter 3 ...] )
{
Method body
}

Creating objects
Class a{
The contents of the class, including properties and methods
}
A a=new a ();

Defining properties
public class Person
{
Modifier Type property name;
}

Naming conventions

A) class: 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. such as the person class, the Membertest class.
b) Method: first letter lowercase. If a method consists of multiple words, all the letters of the first word are lowercase, starting with the second word and capitalizing the first letter of each word. Like Add,addthreeint.
C) Property: The naming convention is the same as the method. Like Age,ageofperson.

The relationship and difference between a member variable and a local variable:

A) both the member variable and the local variable need to be declared (defined) before use.
b) For local variables, it must be initialized before use, and for member variables, it can be uninitialized before use. If you start using a member variable without initializing it, then the member variable of each type has a default initial value
I. The initial value of Byte, short, int, long type is 0
II. The initial value of type float and double is 0.0
III. Char type initial value ' \u0000 '
IV. The initial value of the Boolean type is False

Reference type (reference type): The reference type is used on the object. 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, it is reflected in other references, regardless of which reference modifies the object's properties.

Classes and objects, methods

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.