201671010101 2016-2017-2 "Java Programming"

Source: Internet
Author: User

In the third week, I learned the fourth chapter of the object and class, and a bit more deep understanding of java.

1. Class: A template or blueprint for constructing an object, the process of constructing an object by a class is called creating an instance of the class.

The common relationships between classes are: (1) Dependency (2) aggregation (3) inheritance

2. Object: Object-oriented program is composed of objects, in order to use OOP, must be clear about the object's three main features:

(1) The behavior of an object--what actions can be applied to an object, or what methods can be applied to an object

(2) The state of an object-how the object responds when those methods are applied

(3) Object identification--how to identify different objects with the same behavior and state

The state of the object: each object holds information describing the current characteristics of the large half year, and as an instance of the class, the identity of each object is always different, and the state often differs.

In 3.java, a new instance is often constructed using a constructor, which is a special way to construct and initialize an object, and the constructor name should be the same as the class name, for example, the constructor name of the date class is date, and to construct a Date object, you need to precede the constructor with the new operator.

4. Object variables and objects. An object variable is not an object, and actually does not have a reference object, you must first initialize the variable, you can initialize the variable with the newly constructed object, or you can let the variable refer to an existing object

5. The standard Java class Library contains two classes: one is the date class used to represent the point in time, and the other is the Localdate class used to represent the familiar calendar notation.

6. The constructor differs from other methods in that the constructor is always invoked with the execution of the new operator, and the constructor cannot be invoked on an already existing object to achieve the purpose of re-setting the instance domain. Do not define a local variable with the same name as the instance field in the constructor, such as an example in a book:

Public Employee (String N, double s,...)

{

String Name=n;//error

Double Salary=s;//error

. . .

}

This constructor declares the local variable name and salary. These variables can only be accessed inside the constructor, so the constructor cannot set the salary.

7. Default constructor: When a class is defined, if no constructors are written, the Java compiler automatically adds a default constructor (no parameters) at compile time. The purpose of the constructor is to master the code, using the new operator, to generate the code of the class object, the private property within the class, and not allow objects within the class to pass through the class.

8.this: Equivalent to a constant, abstract represents the current object, defines a method of a class in a class, equivalent to a constructor, followed by a () table referencing the current constructor. Basic format: this. (attribute State) reference

9. Instance members are initialized after a static member, so when an instance accesses a static member, the static member exists, so it can be accessed, and in turn, the access is not true.

10. Set the classpath: It is best to specify the classpath with the-classpath option:

java-classpath/home/user/classdir;.;/ Home/user/archive.jar Myprong

or Java-classpath c:\classdir;.;\. Archive\archives.jar

Knowledge is endless, there is always something to learn, and curious people to dig, to explore. Just today is teachers ' day, by the way I wish teachers happy! Also hope that we can not bear the teacher's expectations, to meet the teacher's request, give the teacher an account, give the family an account, give himself an account.

201671010101 2016-2017-2 "Java Programming"

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.