[Java] "Java Programming Basics Tutorial" Chapter III study

3.1 Class

        Classes in the Java language is a basic reference data types, are basic elements of Java programs. A collection of objects having the same attribute (state) and methods (behavior) called a class, inside which comprises two main portions properties and methods.

Class definitions 3.11

       A class is a reference data type, the user must define the class, then it is declared class instance; the simple data type defined by the Java system, the user can use it to define the data directly, which is the difference between classes and simple data types.

  A class definition contains two parts: the declaration and body.

[Class modifier] class name of the class [ the extends the parent class name] [ the implements Interface Name List]     // class declaration 
{ // body type described 
        [variable declarations member;] 
        [Method declaration;] 
}

 1. Class declaration

Key words for the class, the class name given by the user, but should be consistent identifier naming rules have, in addition to the class name should have a certain sense, a hybrid composed of a few words, the first letter of each word should be capitalized.

Class modifier has a public, private, protected, abstract, final. For the average class usually only two access rights: public and default. With public Modified class, the class can be referenced in different packages, there is a good class can only be referenced in the same package.

3.12 member variables

Type member variable can be any data type in Java, including simple types, arrays, classes and interfaces. In one class, a member variable should be unique.

Declare member variables of the following ways:

[public | protected | private ] [static] [final] type variableName;

1.public class is defined as a member of the public, it may be any type of access

2.protected protected class is defined as a member of the class itself may be, its subclasses, and the same package to access all other classes

3.private class is limited to members of the private and can only be accessed by the class itself

4.default class without any access member defining part of the default access state, and can be accessed by classes in the same package in this class itself

5.static static variables, defining the class member variable is variable (not a modified static member variable called instance variables) can be directly accessed through the name of the class

6.final used to declare a constant, for a final constant defined, its value can not be modified in the program

3.13 member method

1. A method declaration definition method including the method name, return type and parameter. Where the type of the parameter can try simple data types, it can also be a reference data types (also known as compliance with data type)

Java implementation is passed by value, the method takes the value of the parameter, but can not change the value of these parameters.

3.1.4 Constructor

1.public any class can create its real reason

2.private other class can not instantiate this class

3.protected only subclasses and classes in the same package can create instances of it

4. Only the default class in the same package can create instances of it

3.1.5 main method

The main method represents a starting point for a Java application execution. A Java application may consist of one or more classes, but there must be a class defines a main () method

3.2 Object

Object is a system used to describe an entity objective things, it is a basic unit constituting the system. An object package is a set of services to be operated by a set of attributes and a set of attributes of these.

Same class of objects have the same attributes and operations.

Before use objects must be created

The lifetime of an object includes three stages: creation, use and release

3.2.1 Creating objects

1. statement. Assign a reference space, similar to a pointer, a 32-bit address space

2. instantiated. Is accomplished by the new operator

3.2.2 use objects

1. The members access objects

. "" Call can achieve access to member variables and methods by operators

2. The members of the class of objects do

Class member variables can be simple data types, it can also be a target. To an object described as a class member, the attention to the need to allocate memory for the object before use.

Guess you like

Origin www.cnblogs.com/daijux/p/11899901.html