1. Summary of this week's study
1.1 Object-oriented learning to be over, use mind map to draw a mind map or related notes for the core concept of encapsulation, inheritance, polymorphism, and a summary of object-oriented thinking.
Note 1: Keywords and content do not ask for much, but the relationship between the concept of clear, content coverage to the core content of the object can be.
NOTE 2: Less color, not complicated wiring, when necessary to be on the line to explain.
2. Written assignment 1. Clone method
1.1 If you write a class in the Test1 package, Employee
create a new class in the Test2 package, Test
and create a new object in its main in the Test1 package, and then use the Clone method to clone a new object, can you succeed?
As you can see from the employee written in Test1, The Clone () method is protected decorated and can only be used in the same package, and if you want to succeed, you need to use the public adornment instead.
1.2 What should you pay attention to if you want to overwrite the Clone method for your custom class?
Note that using public adornments and custom classes should implement the Cloneable interface.
The methods in 1.3 object objects toString, equals, hashCode
are decorated with public, and the clone
method is protected decorated, try to explain why. Why not declare it as public?
Modified by protected can be accessed only in the class or subclass of this package, improve security, if declared as public then other classes can call this method, so that the original object's properties will be changed because of his call, then chaos, so clone
Methods are protected modified
2. Inner class
2.1 Using an anonymous class and a lambda expression to rewrite the Title object 2-Advanced-polymorphic interface The inner class of topic 7-2. Please map the key code with the running result, please show your number and name in the run result.
2.2. Analyze the following code to answer shapeComparator
what does the object pointed to have to do with the comparator interface?
Comparator<Shape> shapeComparator = new Comparator<Shape>() { @Override public int compare(Shape o1, Shape o2) { //你的代码 } };
The object pointed to by Shapecomparator implements the comparator interface by using an anonymous inner class, overriding the Compare () method
2.3 Topic Set: 6-1 (anonymous inner Class) experimental summary. What do you think is the advantage of using anonymous internal classes?
After implementing the ActionListener interface, you do not need to create a class to implement it, reducing the amount of code
3. PTA Experiment Summary
3.1 PTA (custom interface). and answer: Compared to not write the interface, directly write a class containing IntegerStack
the corresponding method, define the IntegerStack
interface, and then define its implementation of the class what is the benefit of this way?
Experimental summary: The actual is to define a Integerstack interface to implement the function of the stack, the attention is to determine the stack empty stack.
Benefit: The benefit of defining an IntegerStack
interface and then defining its implementation class is that there are many ways to implement this excuse, which facilitates operation.
3.2 PTA (Static inner Class). and answer: When do you think you should use static internal classes? What is the difference between a static inner class and an inner class?
Static inner classes should be used when the inner class has a certain connection to the outer class, and the static members declared in the inner class do not need to depend on the non-static members of the outer class.
The biggest difference is that static inner classes can have static members and methods, but inner classes cannot have static properties and methods
3.3 PTA (inherit cover comprehensive exercise-person, Student, Employee, company). and answer: Collections.sort
What are the prerequisites for using a sort of reference type array?
Using an Collections.sort
array of reference types requires a comparative excuse (comparable or comparator)
4. Big job-continue to improve (try to use the interface to transform your system)
Reference Case-studentdao.zip case
Suppose that in different implementations, the items in the shopping cart are stored in ArrayList, or in arrays.
4.1 Now want to abstract the operation of the shopping cart in the system to the appropriate DAO interface.
4.2 At least two implementations (such as arrays, lists, files) are defined for this interface. Responsible for part of the key code, requires the emergence of names and school numbers.
Using list implementations
Using array implementations
4.3 Give your main program, explaining the benefits of defining DAO interfaces.
The advantage is that after implementing this interface, you can write different classes to implement the required functionality in different ways.
5. Code reading: Persontest.java (abstract, polymorphic, Super)
5.1 Drawing the inheritance relationship of a class
What does the code for the 5.2 main function do?
Sort the age of four objects in ascending order
5.3 What if I remove the super constructor from the subclass?
No, if there is no super constructor, the subclass will default to calling the parameterless constructor of the parent class.
PersonTest.java
where does the 5.4 show polymorphism?
Reference Links:
Persontest.java
Many classes override the ToString () method, such as the student class, the employee class, and so on, where
toString()
the overrides of methods in these classes embody polymorphism
3. Code Cloud and PTA
Topic set: jmu-java-04-Object-oriented 2-advanced-polymorphic interface inner class
3.1. Code Cloud codes Submission record
In the Code cloud Project, select statistics-commits history-set time period, and then search for and
3.2 PTA Problem set complete situation diagram
Two graphs are required (1. Ranking chart. 2.PTA Submission list diagram)
3.3 Count the amount of code completed this week
The weekly code statistics need to be fused into a single table.
201621123069 Java Programming 6th Week of study summary