Object-oriented basis (a)

Class: class

Object: object, instance. Examples of objects of a class and a class is the same meaning.

The relationship between objects and classes:

    1. particular to the general, abstract to concrete

    2. The class can be seen as a template class object, the object can be viewed as a specific instance of the class

    3. The abstract class is used to describe a class of the same type of object, class defines the class object has static and dynamic properties

 

JDK provides a number of classes for use, programmers can also define your own classes.

 

Defined categories:

  1. attribute field. Otherwise known as member variables

      Scope type attribute is the entire body.

      Attribute definition format:

        [Modifier] attribute type = attribute name [Default]

        Modifiers may be omitted, it may be: public, protected, private, static, final

        JAVA attribute type may be any one of any type

        Property named identifier can be lawful,

        It can be initialized, if not its initialization, JAVA use the default value to initialize the definition of member variables.

      Local variables and member variables:

        Different locations declared in a class, a method, in

        Different scope, the method of the current class, the current method. Even with the same name in different methods of local variables it does not matter, independently of each other.

        Member variables have default values, local variables no default

  2. Method method

  3. The method of construction construtor, a special method is automatically invoked when the subject vessels

      Constructor function: initialize (member variables) work as an object

      Constructor is a special method, constructor method name must be the same as the class name. You can not call return in the constructor.

      By calling the new keyword. As with the conventional method, the configuration may be overloaded.

  4. Other: Internal code blocks static block of code blocks

Create an object:

  1. The name of the object class name = new class name ();

Property and method calls the class:

  1. object name. Member variables

  2. object name. Member method

 

 

 

this role:
• this represents the current object itself,
• More precisely, this represents the current object of a reference.
• common method used in this.
Parameter classification of member properties and methods • areas.
• Other methods call the current object (may be omitted)
• Location: Any
• construction method used in this.
• Use this to call other constructors
• Location: The first statement must be
• this can not be used in static methods.
 
 
 
 
In the class, with static member variables declared as static member variables, otherwise known as: class properties, class variables.
• It is a common variable class, belonging to the class, all instances of the shared class, the class is loaded when explicitly initialized,
• For all objects of that class is, static member variables only one. All objects are sharing the class! !
• You can use the "Object Class Properties" to call. However, generally use "class name. Class Properties"
• static method variables placed in area!
• Use the static method declared as static methods
• No object, you can call (class name. Method name)
• When the method is called, does not reference the object passed to it, so the static method can not access non-static members.
• static method can not refer to this in any way and the super keyword
 
 
 
Why package?
• To solve the problem of duplicate names between classes.
• In order to facilitate management class: the appropriate class is located right package!
• package how to use?
• The first class is usually a non-comment statement.
• Package Name: domain name can be written backwards, coupled with the module name, and the internal management class.
• Precautions:
• Package will be added when writing the project, do not use the default package.
• com.gao and com.gao.car, these two packages does not include relationship, are two completely separate packages. Only the latter looks logical
It is part of the former.
 
java.lang
• Java language contains a number of core classes, such as String, Math, Integer, System and Thread, providing common functions.
• java.awt
• comprising a plurality of abstract classes constituting Window Toolkit (abstract window toolkits) These classes are used to build and manage applications
The graphical user interface (GUI).
• java.net
• perform operations include network-related classes.
• java.io
• Contains offer a variety of input / output functionality.
• java.util
• contains utility classes, such as the definition of system properties, using the calendar date-related functions.
 
 
Why import?
• If you do not apply import, if we use like other packages, so only write: java.util.Date, the code is too big, not
Conducive to write and maintain. Other packages can be introduced through the following classes import, which can be directly invoked by the class name in this class.
• import how to use?
• import java.util.Date;
• import java.util *;. // import all the classes in this package. It will reduce the compilation speed, but will not slow down.
• Points to note:
• java default for all classes under import java.lang package, so we can directly use these classes.
• If you import two classes of the same name, only with the package name + class name to show the call-related categories:
• java.util.Date date = new java.util.Date();
 
Static Import
import static java.lang.Math *;. // import all the static properties of the Math class
• import static java.lang.Math.PI; // Math class attributes introduced PI
• We can then be used directly in the program: System.out.println (PI);

Guess you like

Origin www.cnblogs.com/kjsd/p/11774011.html