Understand a case based] [JAVA classes, objects, overloading, encapsulation, inheritance, polymorphism, coverage, abstraction and interface on the concept and the difference between 0 foreword beginners JAVA, there is always a little knowledge to some concepts, mutual confusion, unknown to its design, such as class, object, overloading, encapsulation, inheritance, polymorphism, coverage, abstract class, interface, to facilitate understanding and consolidate, this paper will be based on a case and its deformation, and show the definition of the concept, design, specifications and the matters needing attention, long warned that collection before reading! To control, this paper will points 3 three articles on the above concept, detailed: Class, Object, the Constructor, overloading and packaging concept, medium-length: interpretation of inheritance, coverage and polymorphic concept, next: explain abstract concept and interface, and a comprehensive practice, 1 Class (Class), Object (Object) and the Constructor (Constructor) 1.1 case required to design a rectangular area of the calculator, high input is rectangular (height) and width (width), the output for the area of the Rectangle (area), 1.2 code have the basic knowledge of JAVA syntax can write the following code: Class a Rectangle {//create a Rectangle Class public double height;//define the class member variables public double width; Public Rectangle () {//define a no-parameter constructor can be omitted -} public void calcuArea () {//define classes - area computation System. Out. The println (" area is: "* width + height); }} public class Test {public static void main (String [] args) {Rectangle rec=new Rectangle ();//create a rectangular object, call the constructor rec. Height=1;//height assignment rec. Width=2; Rec.//width assignment calcuArea (); }}//call the area calculation method above 1.3 code analysis code consists of the following concepts: 1, the Class (Class) : Class is a template or blueprint of construction Object, its made up of member variables and methods, the former record data, which records the data of operation process, 2, the Object (Object) : objects are instances of the Class, a Class can have more than one Object, and 3, the Constructor (Constructor) : a Constructor is a special kind of method, used for Object instantiation of initialization, note: the Constructor is always used with "new" keyword, the Constructor method name must be in accordance with the name of the Class! Any class contains at least one constructor, when there is no custom constructor, the compiler will automatically be set to a no-parameter constructor; But if the custom has a constructor, and you need to call a no-parameter constructor, you must manually, the constructor, this () is used to call each other in the same class constructor; Super () is used to call the superclass constructor, must be the first line in the constructor, and cannot exist at the same time, both thinking: although the code implements the basic functions, but its function is not perfect, such as when the user input string for height and width, the code will be an error, then how can in the case of not add trouble to the user to enter the implementation functions? 2 overloading (phrase) 2.1 case required to design a rectangular area of the calculator, for rectangular high and wide input (enter Numbers or strings, assume the user input string is a numeric string), the output for the area of the Rectangle, 2.2 code class Rectangle {public double height; Public double width;//define a no-parameter constructor can be omitted, public Rectangle () {}//define a constructor refs 1 public Rectangle (double height, double width) {this. Height=height;//refer to the current object, this method is used to distinguish parameters of enclosing weight=width; }//definition has a public constructor 2 refs Rectangle (String height, String width) {this. Height=Double. The valueOf (height); This. Weight=Double. The valueOf (width); {} public void calcuArea () System. The out. Println (" area is: "* width + height); }} public class Test {public static void main (String [] args) {Rectangle rec=new Rectangle (1, 2);//create a rectangular object, call the constructor 1 rec. CalcuArea ();//call the Rectangle area calculation method rec1=new Rectangle (" 1 ", "2");//create a rectangular object, call the constructor 2 rec1. CalcuArea (); }}//call the area calculation method above 2.3 code analysis code consists of the following concepts: overloading (phrase) : refers to the class of multiple methods with the same name, but different parameter types or return type of the phenomenon, overloading is for the convenience of the user operation, in the same way of implementing a specific function, at the same time matching of different kinds of parameters in order to meet the scalability and demand diversity, in the code above we implemented the constructor method overloading, perfectly solve the problem of the diversity of user input, but is not confined to the constructor method, it can be applied to any method in the class, note: do not allow the method name and argument types are the same, but different return types, because the program cannot judge which one return, method of parameter type is the same but different order form overloading, such as add (double a, int b) and add (int a, double b), thinking: although the above code solves the question before, but there are still a great potential safety hazard, the user can directly through the "rec. Height" and "rec. Width of rectangle" high and wide assignment, which can result in two days, we don't want to see, one is, when the user input unconventional numerical (such as 1), the result of calculation is meaningless; Second, when the program late changes difficult to maintain, for example, we later want to change the height of the variable type to String type, then must be changed every height assignment places (such as code 1.2), so, how to improve? 3 Encapsulation (Encapsulation) 3.1 case required to design a rectangular area of the calculator, for rectangular high and wide input (number input), and the value should be greater than zero, the output for the rectangular area, at the same time to avoid problems, as described in 2.3 3.2 code class Rectangle {private double height;//private instance fields private double width; Public void setHeight (double height) {//define change method if (height<0 {this. Height=0; } else {this. Height=height; {}} public void setWidth (double width) if (width<0 {this. Width=0; } else {this. Width=width; }} public double getHeight () {//define accessor methods return height; } public double getWidth () {return width; {} public void calcuArea () System. The out. Println (" area is: "* width + height); }} public class Test {public static void main (String [] args) {Rectangle rec=new Rectangle (); Rec. SetHeight (1);//set a high rec. SetWidth (2);//set wide rec. CalcuArea ();//read high and wide System. Out. Println (" is high is: "+ rec. GetHeight () +" wide is: "+ rec. GetWidth ()); }} 3.3 code analysis above code consists of the following concepts: Encapsulation (Encapsulation) : through privatization class member variables, and creating the change of public ownership of the corresponding device (i.e. set independent method of member variables, such as setHeight) and accessor (i.e. read independent method of member variables, such as getHeight) realize the Encapsulation of member variables, design intent: the design of the member variable privatization, the user cannot pass "rec. Height" and "rec. Width of the rectangle's high and wide value assignment and read, change and the design of public ownership of the visitor, the user can call at will, realizes the value assigned to the member variable and read, the changes in the numerical codes, we can set to avoid in the process of user input is error, in the later commissioning, we only need to rewrite the member variables of the class type and the corresponding changes can, without modifying the code for each instantiated object,