Chapter V, VI, VII summary

The fifth chapter summarizes the multi-state
multi-state concept:
refers to allow objects of different classes respond to the same message.
Polymorphic role:
to eliminate coupling between the types.
Requirements:
have inherited, there must be rewritten, parent references to subclass objects.
Polymorphic benefits:
Alternatively, scalability, interfaces, flexibility, simplicity.
Polymorphic Use:
Transformation up <supertype> <reference variable name> = new new <subtype> ();
downcast <subtype> <reference variable name> = (<subtype>) <parent class reference variable>;
Chapter Six abstract summary
abstract class concept:
If a class does not have enough information to describe a specific object, then we call it abstract class.
Syntax:
public abstract class {} class name
characteristics:
1. An abstract class is used inherited
2. abstract class can not be instantiated
3. abstract class can not be abstract methods
abstract methods:
abstract method is referred to by abstract modification method method for the abstract
syntax:
public abstract method return type name (parameter list);
the use of the abstract class abstract methods, note the following:
1. the method must abstract class contains abstract class
2. abstract class is not necessarily abstract method
3. the constructor can not be declared as abstract methods
4.abstract can not be private, static, final, nantive tied for modifying the same method
final use of the following situations:
1) modifying categories:
1. The final modified class can not be inherited
2 can not be inherited, the default, all methods of these classes are final modification
3. If the class does not need to have subclass does not need to be extended, the method does not allow the class to be rewritten, it is modified using such Final
2) modification method:
This class can be inherited, but can not be overwritten
3) Object modification:
Final modification of an object , then reference the object can not be changed, but the value can change
4) modifying variables:
after completion of modification variable, the variable becomes constant, can not be used in subsequent re-assignment
throws
an exception is thrown, the caller handling exceptions
exception handling:
1 The capture and processing through try-catch abnormal
2. continue unusual statement by throws. If the caller does not intend to handle the exception, it can continue throws unusual statement, so the next caller to handle exceptions

Chapter VII summarizes the interface
a more abstract than the abstract class what we call the interface
interface can only write abstract methods
interface is a set of specifications
defined syntax interface:
[modifier] interface Interface 1 Interface Name of the Father, the Father Interface 2 .. ... {
// definition of common sense
//} method defined
class that implements the interface syntax:
calass implements parent class name for the class name implements interfaces 1, 2 ...... Interface {
//} class members
can abstract interface the method, we can be omitted after java1.8 abstract but it is an abstract method
has no constructor interface
interface variables: public Stratic final
how to use the interface (implements) implements the interface
if a class implements an interface, then we to override all the methods inside
our class can implement multiple interfaces, but you have to rewrite all the methods in an interface you implement
our interface multiple inheritance can be separated by commas
if we are to achieve the interface is multiple inheritance, then we will implement the interface for all functions (the interface which is written is a function of a)
If you have two interfaces there are two methods name With abstract method, then in succession when only one needs to be rewritten
interface role:
1, plus how the code scalability
2, reduce the degree of coupling code (what we call the tightness)

 

Guess you like

Origin www.cnblogs.com/Lxf19990923/p/11700383.html