javaOO-- inner classes, polymorphism, abstract

1, the number of files and the number of class-independent java file, but rather related to the number of java class files
2, regardless of the name of the class file name of the Java file, but with the class name of the class of about
3, if class is public, and its name must be consistent with java file name, so a java file can have only one public class
Inner class class file named: external internal class class class class name $ name .class
Partial inner class
writing position: a method which is defined in the outer class.
In addition to special local inner class defined position, he is still a complete class.
There is a special case of a local inner classes, anonymous inner class called
local inner class class file named: external class class class class name $ digital internal name .class
Anonymous inner classes --- no class name
it is the definition given in the new class of objects at the same time. It can only produce an object with this time

Polymorphic
sentence description polymorphism: the same behavior, different implementations.
Polymorphic Category:
 Static polymorphism: the compiler, the system will be able to decide which method calls (method overload meet the same behavior, different implementations, is a reflection of the multi-state, multi-state static)
 dynamic polymorphism: Run the system can dynamically determine the meaning of object methods
To compile, can run through, eventually only two cases in memory:
1, references to the parent class subclass object
2, the references to this class object class
This class reference to an object of this class
 compile: because the subclass and superclass is is - a relationship, so subclass object is the parent class type, no problem at all.
 By running, since each subclass object in the selection process, it is based on memory in a superimposed manner.
  To produce the parent object portion (parent class is a complete object), and then superimposed unique subclass.
  So, this subclass object has all the content type definition of the parent class.
The only question is:
 when using the parent class reference point to a subclass object, which can only be operated references to property or method of the object who inherits the parent class.
 This sub-class object can not operate its own unique properties and behavior.
--- The key exception is dynamic polymorphic
 If the subclass overrides the behavior of the parent class, so long as the object is a subclass of objects, no matter what the reference to point (parent Ye Hao, Ye Hao subclass), the effect will be subclasses override the effect.
Dynamic polymorphism:
 1, to the parent class reference
 2, because the parent class reference only partially visible from the parent class, so this method must be re-define the parent body, and then overridden by subclasses.
Dynamic binding technique:
 reference The parent runtime type variable pointing object actually execute a corresponding method subclass it, in order to achieve polymorphism.
Instanceof Object data types
 --- determine whether an object is a data type
 --- return type: true, false
Abstract methods
 Some methods of the parent class, can only determine the method declaration.
 (Ie a total of subclass What is the name, what parameters, return values Why type, access modifier what should be)
 but can not determine the method implementation (because different specific implementation subclasses, all specific implementation should let a subclass overrides)
Syntax: re-writing method Qualifiers abstract modifier, the method can not be achieved with a portion (including the inability {})
in the parameter list Finally the method; End
Effects:
 It may be a compiler, mandatory implementation subclass must override abstract methods from the parent class.
 (A subclass of abstract class must override its abstract methods, unless the subclass is also abstract class)
Related concepts: the ultimate method
The relationship between abstract classes and abstract methods:
(1) there must be an abstract method of an abstract class method
(2) may not have abstract methods abstract class
 but from the design, if an abstract class without abstract methods to lose the sense of the abstract .
(3) can pass through abstraction inherited.
Abstract class:
 some kind of design uses the parent class is used to do, instead of generating object.
 To prevent this, this kind of design is an abstract class.
Syntax: add a modifier in front of the class keyword abstract
Impact: - Abstract class just can not produce objects, but does not affect other content
 1, which has attributes, behavior, structure, initialization block, inner classes can see
 2, you can still point to the object subclasses, access common property behavior.
 3, the relationship between subclasses and still is -a, it should be said that even before taking into account the relationship is-a design of only the parent, then the parent object generated by the need to determine whether the set is abstract
The benefits of abstract classes and abstract methods
 from the design point of view, an abstract method in the parent class, the class can force any child to achieve a particular behavior. Subclass inherits an abstract method if you want to instantiate an object, you must override this method.

Guess you like

Origin www.cnblogs.com/libobo22/p/11656057.html