Java Personal Learning Notes: object-oriented thinking

Source: Internet
Author: User

Class classes and Object objects are core object-oriented concepts.

A class is a description of a kind of thing, an abstract, conceptual definition.

An object is an entity that actually exists for that kind of thing. This is also known as an instance.

Java uses classes to describe things, and defining classes is actually defining members and variables in a class that includes

Properties: member variables in the corresponding class field= property = Member Variable

Behavior: The member method in the corresponding class method= (member) method = function

Variable classification

In a method body, a variable declared within a class is called a member variable.

Variables declared in the body of a method are called local variables.

The local variable, in addition to the formal parameter, needs to be displayed for initialization. Member variables have default initialization values.

Method

A method is an abstraction of the behavior characteristics of a class and an object, and it becomes a function.

The Java method cannot exist alone and must exist in the type.

The return statement passes the returned value. No return value is void

Stack

Referencing local variables for an object

Heap

What's new (including member variables)

Creation and use of objects

To create a new object using the new + Builder

Access object members, including properties and methods, by using the object name. Object member. )

If you create multiple objects of a class, each object has its own set of replicas for the properties defined in the class and does not interfere with each other.

Access mechanism of the class

Access mechanism in a class: a member variable in a class can be accessed directly in a class. (The static method accesses a non-static method to compile an error.) )

Access mechanisms in different classes: first create the object to access the class, and then use the object to access the members defined in the class.

Anonymous objects

We can call the object's methods directly without defining a handle to the object. An object of this kind is called an anonymous object.

New person (). Eat ();

You can use anonymous methods if you only need to make one method call to an object. The anonymous object is often passed as an argument to a method call. 、

Overloading of methods

In the same class, more than one method of the same name is allowed, as long as the number of arguments or parameter types are different

Regardless of the return value type, look only at the parameter list, and the argument list must differ.

Java Personal Learning Notes: object-oriented thinking

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.