. In the Java specification, it is generally overridden that the Equals () method should overlap the hashcode () method.ToString () methodThe ToString () method is another important method defined in the object class, which is the string representation of the objects, and the syntax is:Public String toString ()The return value is a String type that describes the information about the current object. The ToS
Java Tour (vi)--single case design pattern, inheritance extends, aggregation relationship, child parent class variable relationship, Super, overlay
Java also more and more deep, everyone refueling it! Let's take a step
I. Single-CASE design mode
What is design mode?
There are 23 desig
).
Multiple inheritance of interface
In the inheritance of Java classes, a derived class can have only one base class. In other words, a class cannot inherit more than one class at a
Source: Click to open the link
The order of Java class initialization is often confusing, and now this article tries to give the JVM an explanation by experimenting with the initialization order of classes in the Java non-inheritance and inheritance relationships from the JV
The order in which Java classes are initialized is often confusing, and now this article attempts to experiment with the initialization order of classes in Java non-inheritance and inheritance relationships from a JVM perspective, trying to give an explanation of the JVM's perspective.initialization order in non-
{System.out.print (arr[x]+","); } } } /*** method to get the maximum value in the array *@paramArr Array *@returnreturns the maximum value in an array*/ Public Static intGetmax (int[] arr) { //the element that joins the array is the maximum value intmax = Arr[0]; for(intx=1;x){ if(maxArr[x]) {Max=Arr[x]; } } returnMax; } /*** Get the index of the values in the array *@paramthe values in the ARR array value array *@r
Interface Inheritance interface Inheritance (inheritance) is similar to class inheritance, with the addition of new interface method prototypes based on inherited interface. For example, we use Cup as the original Interface:interface cup{void Addwater (int w);void Drinkwater
1. Selection between combinations and inheritanceBoth combination and inheritance allow child objects to be placed in a new class, and the combination is explicitly done, whereas inheritance is implicitly done.Combinatorial techniques are typically used in situations where you want to use the functionality of an existing clas
members of the inherited class.Parent class/Superclass--inherited class; subclass/Derived class--new class generated by inheritanceRelationship of parent class and child class:A. Subclasses automatically have all members of the parent c
encapsulation is to separate the designer of the object from the designers of the objects, and the user does not need to know the details of the implementation of the behavior, only to access the object with the interface provided by the designer. At the same time, reduce the dependencies between the parts of the program, reduce the complexity of the program, because it hides the details of its internal information, so that internal information is not easy to be destroyed, security has been gua
classes and ancestor classes are not strictly distinguished, and child classes are not required.
2. Single inheritance and multi-Inheritance
In the real world, when we classify in a certain way, the hierarchy of classes is usually represented as an inverted tree. The specific characteristics are as follows: each node in the tree can have one parent class or no p
, find a place2, order3, serving4, open Eat5, digestion6, excretion}private void Digest () {}......=========================StaticAll members of the class (properties and methods) are divided into 2 types:Static member = Class MemberDescribes the characteristics of the class itself.Access is accessed using the class na
{public staticVoid main (string ARGs []) {A. func (); // direct call }}
10. Introduction to final.
VariableDeclared as final, can prevent modifying the content of the variable, essentially a constant.
All final variable names are in upper case, encoding conventions.
Final variables must be initialized when declared. Two methods are used for initialization. One is to assign a value during declaration, and the other is to assign a value to the constructor.
Method parameters and local variablesIt
inheritance relationship , that is, the child class overrides the parent class method. It requires that both methods have the same number and type of arguments and return value types , which are called method overrides.(A subclass requires permission for a method override on a parent class, and the subclass method mus
of the parent class first.The first sentence of our custom class constructor must be super (xx,...), if not, then the first sentence must be this (xx,...) To call another constructor of this class.If the subclass constructor does not explicitly call super (), then Javac will automatically insert super (), which is the constructor with no arguments to the parent class.For constructors, all constructors in a
();
}
}
For the order of execution above
1. Static blocks of the parent class
2. Sub class static Block
3. Non-static blocks of the parent class
4. The method of constructing the parent class without parameters
5. Non-static blocks of subclasses
6. Sub-class
5.1 Subclass and Parent class1 Java does not support multiple inheritance, that is, a subclass can not inherit from multiple parent classes at the same time, while C + + can.It is customary to call the relationship between the subclass and the parent class "Is-a"2 during the declaration of a class, a subclass of a
Inheritance is very tightly combined with Java (and other OOP languages). We have introduced the concept of inheritance in the 1th chapter, and have been used from time to moment in the chapters before this chapter, as some special occasions require inheritance. In addition, the creation of a
Public String toString () { return "Dog[age" +age+ "]";}Equals () methodThe source of the comparison is whether the object reference to the unified block memory address,A subclass can be modified to compare the values of two objects for equality. This can be modified:1 //Parent Class2 Public classAnimal {3 Public intAge ;4 5 6 }7 8 //sub-class9 Public classDogextendsAnimal {Ten @Override One Public Booleanequals (Object obj) { A if( This==obj)//determine if the referenced
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.