Java-- object-oriented knowledge summary

 

 

Object-oriented three main lines:

A, classes and components

1. class and class relations:

java program is focused on the type of design.

Class from a code perspective: parallel relationship!  

From the implementation design: association, inheritance, aggregation relationship

class A{

 

}

class B{

   A  a = new A();

}

2. Class ingredients: Properties Method inner class constructor code blocks

2.1 Properties:

① classification variables: member variables (attributes Field) vs local variables (formal parameters of the method, the internal method, the internal code blocks)

② data types: basic data types (8 types, different types of data corresponding to a default initialization value vs reference data types (array, classes, interfaces default initialization value is null)

③ declaration format attribute: data type qualifier initialized variable name = value; // java data is strongly typed languages

④ attribute assignment operations: default initialization, explicit initialization, initialization code block, the initialization of the constructor call assignment method or property

2.2 Method  

① Format: modifiers (other keywords: static / final / abstract) return type method name (parameter list) {

} // Method body

Rewrite overloaded (overload) vs method ② method (override overwrite)

③ Method of parameter passing mechanism: value passed (difficult)

2.3 constructor  

① the role of the constructor: 1. Create a class member variable object 2. The object initialization

② also be overloaded constructor.

2.4 block  

① main role: to initialize class member variables

② Category: static vs non-static block of code blocks

2.5 Internal class  

① classification: (class method declared inside) members of the inner class (members of the members of static vs non-static) vs local inner class

② to master: how to create objects within the class members (such as: Creating classes and objects Bird Dog class), how to distinguish between external call

Category class or internal variables (variables especially when the same name), using local inner classes (see TestInnerClass1.java)

3. The class is initialized (class of object creation)

3.1 How to create an object class.

如: Person p = new Person();  Date d = new Date();

3.2 Memory Analysis:

① stack: local variables, object reference name, reference name of the array

  Heap: new out of the "stuff"

  Method :( string constant pool area)

  Static fields: storage class static variable

② how to understand the process of object creation loaded in memory (to understand)

3.3 subclass object instantiation whole process: SubClass new new SubClass SC = ();

Second, the object-oriented three characteristics:

1. Encapsulation:

① through privatization class member variables, to call and modified by public getter and setter methods

② may also be "packaged" to other classes of structure

③ permission modifiers: public protected default private

2. Inherited:

① A by having a class inherits from another class B, class B can obtain the configuration (major: properties, methods, constructors). Subclasses: class Parent Class A: Class B

②java inheritance of classes: single inheritance.

3. Polymorphism:

① reflect: overloaded and the overriding method; polymorphism subclass object Person p = new Student ();

② subclass object polymorphism: a virtual method call.

③ upward transition downcast Student s = (Student) p; 

// advice before downward transition: if (p instanceof Student) avoid ClassCastException exception occurred

Third, other keywords:

1.this: modifying properties, methods, constructors. He said: the current object or objects currently being created.

2.super: modifying properties, methods, constructors. Explicit corresponding call the parent structure, in particular child-parent class has the same name methods, properties

3.static: modifying properties, methods, code blocks, inner classes. With loads and loads of class!

4.final: Modified classes, attributes and methods. Means "final"

5.abstract: Modified class, method

6. interface: represents an interface (the interface is a parallel type structure). At the same time "implements" a relationship between classes and interfaces.

7.package import …

8.abstract: not modified property, constructor, not shared with final static private.

 

 

 

Guess you like

Origin www.cnblogs.com/superjishere/p/11839894.html