java - Object Oriented

A method of overload (1)

  1, different parameter list: different types and number of different sequence

  2, the method overloading and permission modifier, return type, irrespective of the parameter variable name

  3, how to determine which method is invoked: method name parameter list +

  4, if the same type (parameter type) then called directly, if not, look at whether there are ways you can improve the automatic type

A. Deformable Reference (2)

  

/ * 
 * Reference deformable 
 * 
 * format: Method name (variable type variable names ...) 
 * 
 * Description; 
 * 1. The number of reference deformable may be one or more 0 
 * reference deformable 2 the bottom layer is an array, and an array of identical manner value 
 * 3. If the reference array and deformable as the variable type, does not constitute an overload 
 * 4. only one of an array reference deformable, and is the last parameter 
 * / 
public  class MoreArgs {
     public  static  void main (String [] args) { 
        ComputerNumber CN = new new ComputerNumber (); 
        cn.sum ( l, 2,3 ); 
        cn.sum ( 0 ); 
        cn.sum ( 1,2, 3,4, 5 ); 
        
    } 
} 

class{ComputerNumber
     // deformable underlying parameter is an array 
    public  void SUM ( int ... Numbers) {
         int SUM = 0 ;
         for ( int I = 0; I <numbers.length; I ++ ) { 
            SUM + = Numbers [I] ; 
        } 
        System.out.println (SUM); 
    } 
}

 

Two .package package

  package role: java for unified management and division of all classes, so only the package concept
Description:
  Role: java class in order to unified management, so only the package concept
  package name:. com domain. project name module name
  . "": one representing each parent directory. ""
  class name: class name in different packages may be the same class name can not be the same under the same package
  location: first line of the source file

Three .import keyword

 Keywords: import
  1. designated classes and interfaces in the package using explicit introduced in the source file import
  2. Statement Disclaimer between classes and packages
  3. If you need to import multiple classes and interfaces, then parallel a plurality of statements to explicitly import
  4. example: use java.util * manner, import all the classes and interfaces of the package util
  5. If the class or interface is introduced under java.lang package, or the current under the package, you can omit this import statement
  6. If you use the same name in different package of classes in your code, you need ways to use the full class name of the class indicates that the class is called
  using 7.import static combination of: call specifies the class property or method or the static interface
  8. If the class has been introduced under java.a packet, then if the class requires a sub-packets in the packet, it still needs to import

IV. Object-Oriented

  1) Object-oriented and process-oriented:  

    > Oriented process: it emphasized that the functional behavior
    > object-oriented: the function package gold objects, function objects have emphasized

  2) Object-oriented three characteristics: encapsulation, inheritance, polymorphism

  3) Java four permission modifiers public, protected, private, default

 


V. Why use encapsulation:
  A After you create an object, we can assign to a property by property name object name, only to limit the type and scope of the assignment variables... However, in development we tend to have a lot of restrictions. These restrictions can not be restricted in a statement at the property. We take the following methods:
    1. restrictions on property rights. This prevents external properties in the class is invoked
    2. Create a method, by means of the assignment of property. Condition can be limited in the method.

  b reflected encapsulation (narrow sense):
    1. privatization property
      Note: The method will attribute assignment naming convention to setXxx, the method for obtaining the value of the attribute named as getXxx, whether set or get method are common methods
    2. set / get (set / get the method is to facilitate understanding the role of the method) and the method of obtaining the attribute assignment
  c reflect the encapsulation (broadly).
    1. permission modifier: public private protected default
    2. class default public and can only be modified
    3. the four permission modifier can be modified: properties, methods, internal class constructor

VI. Wherein constructor
  1. It has the same name as the class
  2. It does not represent the return type. (Declared void and different)
  3. can not be static, final, synchronized, abstract, native modification, can not have a return statement returns the value

The role of constructor: create objects; to initialize the object

 

*   Assignment way to the property?
 * Assignment 1. The display default assignment (i.e., assignment statements) 3. Object Name attribute name / name object name Method 4. Constructor assignment.
  *       
 * Assigns them sequentially: 1 -> 2 -> 4 -> 3

 

 

    

Guess you like

Origin www.cnblogs.com/jiujiang/p/11563856.html