1:final Keywords (master)
(1) is the final meaning, can be modified class, method, variable.
(2) Features:
A: It modifies the class and cannot be inherited.
B: It modifies the method and cannot be rewritten.
C: The variable it modifies is a constant.
(3) Interview Related:
A: Local Variables
A: The base type value cannot be changed
B: The reference type address value cannot be changed, but the content of the object can be changed
B: Timing of initialization
A: can only be initialized once.
B: Common given values
Definition of the time. Recommended
Constructs the method.
2: Polymorphism (mastering)
(1) The different states that the same object manifests at different times.
(2) The precondition of polymorphism:
A: There is a succession or realization of the relationship.
B: There are methods to rewrite.
C: There is a parent or parent interface reference to the child class object.
Classification of polymorphic:
A: Specific types of polymorphism
Class Fu {}
Class Zi extends Fu {}
Fu f = new Zi ();
B: Abstract polymorphic
Abstract class Fu {}
Class Zi extends Fu {}
Fu f = new Zi ();
C: Interface polymorphism
Interface Fu {}
Class Zi implements Fu {}
Fu f = new Zi ();
(3) Features of member access in polymorphic states
A: Member variables
Compile look left, run look left
B: Construction method
The construction of the subclass will have access to the parent class construction by default
C: Member Method
Compile look left, run look right
D: Static method
Compile look left, run look left
Why?
Because the member method has overrides.
(4) The benefits of polymorphism:
A: Improve the maintenance of code (inheritance embodies)
B: Improve code Extensibility (polymorphic representation)
(5) The disadvantages of polymorphism:
The parent cannot use the unique features of the child.
Phenomenon:
A child can be used as a parent, and the parent cannot be used as a child.
(6) Transformation in polymorphism
A: Upward transformation
From child to Parent
B: Down transformation
From parent to Child
(7) The case of Confucius pretending to be a father helps us understand polymorphism
(8) Multi-state exercises
A: Cat and Dog case
B: Teacher and student case
3: Abstract class (Master)
(1) To extract a number of common things into a class, this is the practice of inheritance.
But there are many things that are common, in some cases, method declarations, but method bodies.
That is, the method declaration is the same, but each specific object is not the same when the concrete implementation.
Therefore, when we define these common methods, we cannot give the concrete method body.
A method that does not have a concrete method body is an abstract method.
In a class, if there is an abstract method, the class must be defined as an abstract class.
(2) Characteristics of abstract classes
A: Abstract classes and abstract methods must be modified with the keyword abstract
B: Abstract classes do not necessarily have abstract methods, but classes with abstract methods must be abstract classes
C: Abstract class cannot be instantiated
D: Subclass of Abstract class
A: is an abstract class.
B: is a specific class. This class must override all abstract methods in the abstract class.
(3) Characteristics of abstract class Members:
A: Member variables
There are variables, there are constants
B: Construction method
There are construction methods
C: Member Method
There is abstraction, there is non-abstract
(4) Practice of abstract classes
A: Cat and dog case exercise
B: Teacher Case Exercises
C: Student Case Exercise
D: Employee Case Exercise
(5) Some small problems of abstract class
A: Abstract class has a construction method, can not be instantiated, then what is the use of the construction method?
Initialization for subclass access to the parent class data
B: What is the use of a class if it has no abstract method but is defined for abstract classes?
To keep the object from being created
C:abstract cannot coexist with which keywords
A:final conflict
B:private conflict
C:static no meaning
4: Interface (Master)
(1) Looking back at cat and dog cases, they only provide some basic functions.
For example: Cat drill fire ring, dog high jump and other functions, not the animals themselves have,
Is trained in the back of the training, this extra function, Java provides an interface representation.
(2) Features of the interface:
A: interface with keyword interface decoration
Interface interface Name {}
B: Class implementation interface with implements modification
Class name implements interface name {}
C: interface cannot be instantiated
D: Implementation class of the interface
A: is an abstract class.
B: is a specific class that must override all the abstract methods in the interface.
(3) member features of the interface:
A: Member variables
can only be constants
Default modifier: public static final
B: Construction method
No construction method
C: Member Method
It can only be abstract.
Default modifier: Public abstract
(4) Classes and classes, classes and interfaces, interfaces and interfaces
A: Classes and classes
Inheritance relationship, can only be single-inheritance, multi-layer inheritance
B: Classes and Interfaces
The implementation of the relationship, can be implemented alone, or more.
You can also implement multiple interfaces while inheriting a class
C: Interface and interface
Inheritance, can be single-inheritance, or multiple inheritance
(5) The difference between abstract class and interface (self-completion)?
A: Member Differences
Abstract class:
Interface:
B: Relationship differences:
Classes and classes:
Classes and Interfaces:
Interfaces and interfaces:
C: Different design concepts
Abstract class: Is a, which is defined in the abstract class as a generic function.
Interface: Like a, an interface that defines an extension function.
(6) Practice:
A: Cat and Dog case, join the high jump function
B: Teacher and student case, add smoking function 0
Java_day09 (final, polymorphic, abstract class, interface)