This is my lesson Web Java course notes, the original video link is: http://www.imooc.com/learn/124
4-1 polymorphism in Java
definition: Multiple forms of an object
1. Quoting polymorphicReferences to the parent class can point to objects of this class;a reference to the parent class can also point to the object of the child class
inheritance is the basis of polymorphism implementation
2. Method PolymorphismWhen you create this class object, the method that is called when you create a subclass object for this class method is a method that is overridden by a subclass or an inherited method
PS: You cannot call a method unique to a subclass
4-2 Conversion of reference types in polymorphic
1. The upward type conversion (implicit/automatic type conversion), is a small type to a large type of conversion. (There is no risk) 2. Downward type conversions (coercion type conversions), are large types to small types. (There are risks, such as data overflow, etc.) 3.
instanceof operatorTo resolve the type of reference object and to avoid the security of type conversions
Operation Result:
4-3 Abstract classes in Java
1. Syntax DefinitionsUse before abstract class
abstract keyword Modified, the class is an abstract class.
2. Application ScenariosA. In some cases, a parent class simply knows what methods its subclasses should contain, but does not know exactly how these subclasses implement these methods. B. Abstract an abstract class from multiple classes with the same characteristics, using this abstract class as a template for subclasses, thus avoiding the arbitrariness of sub-class design.
3. RoleRestriction subclasses must implement some methods, but do not care about implementation details
4. Usage rulesA. Abstract defines an abstraction Class B. Abstract defines an abstraction method that is only declared and does not need to implement C. Classes that contain abstract methods are abstract classes D. Abstract classes can contain ordinary methods, or there can be no abstract method
E. Abstract classes cannot be created directly, you can define reference variables
4-4 interfaces in Java
1. Interface Concepts▲ Interfaces can be understood as a special class that consists of global constants and common abstract methods.▲ A class is a concrete implementation body, and an interface defines a batch of classes that are required to obey
Specification, the interface does not care about the internal data of these classes, nor does it care about the implementation details of the methods in these classes, it only stipulates that certain methods must be provided in these classes.
2. Interface Definition▲ Unlike class definitions, the definition interface no longer uses the class keyword, but instead uses the
Interface Keywords。▲ Basic syntax for interface definition: [modifier]<abstract> Interface Interface Name [extends parent interface 1, parent interface 2] {0 To multiple constants define 0 to multiple abstractions Definition of the method} ▲ Interfaces are used to be inherited, implemented, modifiers are generally recommended to use public Note: You cannot use private and protected to decorate interfaces▲ interface can inherit multiple parent interfaces
3. Interface Definition (2)
▲ Constant
the properties in the interface are constants, and the system automatically adds the public static final modifier even when the definition is not added. ▲ Method the method in the interface can only be an abstract method and is always used, even if the public abstract modifier is not added to the definition, the system is automatically added.
4. Using the interface ▲ A class can implement one or more interfaces to implement an interface using
Implements Keywords。 A class in Java can only inherit one parent class, which is not flexible enough to be supplemented by implementing multiple interfaces.
The syntax for inheriting a parent class implementation interface is: [Modifier] class name
extends parent class implements interface 1, interface 2 ... {The class body part///If you inherit an abstract class, you need to implement an abstract method of inheritance, to implement an abstract method in an interface. If you want to inherit the parent class, the inherited parent class must precede the implementation of the interface.
when an interface is named, it is usually preceded by an "I" to distinguish it from the normal class
▲Interfaces are often used in conjunction with anonymous inner classes anonymous inner classes are internal classes that do not have names, and are used to focus on implementations rather than on the name of the implementation class
Syntax format: Interface i = new Interface () {public void method () {System.out.println ("Anonymous inner class implements the interface Way"); } }
4-5 Introduction to UML
1.UML ConceptUnified Modeling Language (UML) is also known as a unified Modeling language or a standard modeling language. is a graphical language that supports modelling and software system development. Provides modeling and visualization support for all phases of software development.
2.UML Common Illustrations
▲ use case diagram (Diagram) use case diagrams can visualize how systems meet the business rules they collect, as well as specific user requirements.
▲ Sequence diagram (the Sequence Diagram)
Sequence diagrams are used to display these interactions between objects in a series of sequences that occur interactively.
▲ class Diagram (the class Diagram)
UML class diagrams, business logic, and all supporting structures are used together to define the entire code structure.
3.UML Common modeling ToolsVisio, Rational Rose, and powerdesign have the widest range of three modeling tools to use.
Java Getting started the second quarter the fourth chapter polymorphism