Object-oriented thinking features:
* A: A thought that is more in line with our thought habits
* B: Complex things can be simplified
* C: Turn us from performer to conductor
* Character has been converted
Object-oriented development, design, and features:
* A: Object Oriented development
* is constantly creating objects, using objects, directing objects to do things.
* B: Object oriented design
* In fact, it is the relationship between managing and maintaining objects.
* C: Object-oriented features
* Package (encapsulation)
* Inheritance (Inheritance)
* Polymorphic (polymorphism)
Concepts of classes and objects:
* A: Class: is a set of related properties and behaviors
* B: Object: Is the concrete embodiment of this kind of thing
* C: for example:
* Class Students
* An object specific to a student is an object
The difference between a member variable and a local variable:
* A: Different positions in the class
* Member Variable: Outside of method in class
* Local Variables: In the method definition or on the method declaration
* B: The location in memory is different
* Member variable: In heap memory (member variable belongs to object, object into heap memory)
* Local variables: in stack memory (local variables belong to method, method into stack memory)
* C: Different life cycle
* Member variable: As the object is created, disappears as the object disappears
* Local Variables: As the method is called, it disappears as the call to the method is complete
* D: Different initialization values
* Member variable: has default initialization value
* Local Variables: There is no default initialization value, it must be defined, assigned, and then used.
* Precautions:
* The local variable name can be the same as the member variable name, when used in the method, using the nearest principle.
Overview and application of Anonymous objects:
* A: What is an anonymous object
* B: Anonymous Object Application Scenario
* A: Call the method, just call it once.
* So what is the benefit of this anonymous invocation?
* Save Code
* Note: It is not appropriate to call multiple times. The anonymous object call is complete garbage. Can be reclaimed by the garbage collector.
* B: Anonymous objects can be passed as actual parameters
Overview and features of the Private keyword:
Private keyword Features
* A: is a permission modifier
* B: Can modify member variables and member methods
* C: Members modified by them can only be accessed in this class
Overloading of construction methods and considerations:
* B: Construction Method considerations
* A: If we do not give a construction method, the system will automatically provide a non-parametric construction method.
* B: If we give a construction method, the system will no longer provide a default parameterless construction method.
* Note: This time, if we still want to use the method of non-parametric construction, we must give it ourselves. It is recommended that you always give the method of non-parametric construction
* C: Two ways to assign a value to a member variable
* A:SETXXX () method
* B: Construction method
Features of the Static keyword:
* Features of A:static keywords
* A: Loaded with the load of the class
* B: Precedence over object existence
* C: Shared by all objects of the class
* Example: Students in our class should share the same class number.
* In fact, this feature is also telling us when to use static?
* If a member variable is shared by all objects, it should be defined as static.
For example
* Water dispenser (with static modification)
* Water Cup (cannot be modified by static)
* D: Can be called by the class name
* In fact, it can also be called by the object name itself.
* Calling with class name is recommended.
* Content that is statically modified is generally referred to as: Class-related, Class-member
Static considerations:
* A:static Precautions
* A: There is no this keyword in the static method
* How to understand it?
* Static is loaded as the class loads, and this is present as the object is created.
* Static than object exists first.
* B: Static methods can only access static member variables and static member methods
* Static method:
* Member variables: Only static variables can be accessed
* Member method: Only static member methods can be accessed
* Non-static method:
* Member variable: can be static or non-static
* Member method: However, it is a static member method, or it can be a non-static member method.
* Easy to remember:
* Static can only be accessed statically.
The difference between a static variable and a member variable:
* A static variable is also called a class variable member variable also called an object variable
* A: Belong to different
* Static variables belong to classes, so they are also referred to as class variables
* Member variables belong to an object, so also known as instance variables (object variables)
* B: Different locations in memory
* Static variables are stored in the static area of the method area
* Member variables are stored in heap memory
* C: Memory occurrence time is different
* Static variables are loaded as the class is loaded and disappear as the class disappears
* Member variables exist as the object is created and disappear as the object disappears
* D: Call different
* Static variables can be called through the class name, or through object invocation
* Member variables can only be called by object name
Transition up and down in polymorphic:
* Parent class is animal, subclass is Cat
* Animal a = new Cat (); Upward transformation
* Cat C = new Animal (); wrong
* Cat C = (cat) A; Down transformation
An overview of abstract classes and their characteristics:
* B: Abstract class features
* A: Abstract classes and abstract methods must be decorated with the abstract keyword
* Abstract class Name {}
* Public abstract void eat ();
* B: Abstract classes do not necessarily have abstract methods, classes with abstract methods must be abstract classes
* C: Abstract class cannot be instantiated so, how does an abstract class instantiate?
* Instantiated by a specific subclass in a polymorphic manner. In fact, this is a polymorphic, abstract polymorphism.
* D: Subclass of abstract class
* or an abstract class
* Either rewrite all abstract methods in the abstract class
Member features of abstract classes:
* A: Member characteristics of abstract classes
* A: Member variable: it can be either a variable or a constant.
* B: Construction method: Yes.
* For subclasses to access the initialization of the parent class data.
* C: Member method: can be either abstract or non-abstract.
B: Member method attribute of abstract class:
* A: The abstract method enforces what subclasses do.
* B: Non-abstract method subclass inherited things, improve code reusability.
An overview of the interface and its features:
* A: interface overview
* From a narrow point of view, it means interface in Java.
* From a broad perspective, the external rules are all interfaces
* B: Interface Features
* A: interface with keyword interface representation
* Interface interface Name {}
* B: Class implementation interface with implements representation
* Class Name implements interface name {}
* C: interface cannot be instantiated
* So, how does an interface instantiate?
* Instantiate in a polymorphic manner.
* D: Sub-class of the interface
* A: Can be an abstract class. But it doesn't make much sense.
* B: Can be a specific class. To override all abstract methods in an interface. (Recommended scheme)
Member features of the interface:
* A: interface member features
* Member variables, only constants, and static.
* Default modifier: public static final
* Suggestion: Give yourself manually.
* Construction Method: Interface has no constructor method.
* Member method: can only be an abstract method.
* Default modifier: Public abstract
* Suggestion: Give yourself manually.
The relationship between classes and classes, classes and interfaces, interfaces and interfaces:
* A: Class and Class, class and interface, interface and interface relationship
* A: Classes and classes:
* Inheritance relationship, can only be single-inheritance, multi-layer inheritance.
* B: Class and Interface:
* Realize the relationship, can be single implementation, can also be implemented more.
* and you can also implement multiple interfaces while inheriting a class.
* C: Interface and Interface:
* Inheritance relationship, can be single-inheritance, can also inherit more
The difference between an abstract class and an interface:
* A: Member Differences
* Abstract class:
* Member variable: can be variable, can also be constant
* Construction Method: Available
* Member method: can be abstract or non-abstract
Interface
* Member variable: can only be constant
* Member method: can only abstract
* B: Relationship Difference
* Classes and Classes
* Inheritance, single inheritance
* Classes and Interfaces
* Implementation, single implementation, multi-implementation
* Interface and interface
* Inheritance, single inheritance, multiple inheritance
* C: Differences in design concepts
* Abstract classes are inherited as follows: "is a" relationship. The common function of the inheritance system is defined in the abstract class.
* The interface is implemented as follows: "Like a" relationship. The extension functionality of the inheritance system is defined in the interface.
Java object-oriented attention point 1