Homework 06 - Interfaces, Nested Classes

1. This week's learning summary

1.1 Object-oriented learning has come to an end. Please use the mind map to draw a mind map or related notes with encapsulation, inheritance, and polymorphism as the core concepts to summarize the object-oriented thinking.
Note 1: There are not many keywords and content, but the connection between concepts should be clear, and the content should cover the core content of object-oriented.
Note 2: The color should be less, and the connection should not be complicated. When necessary, it should be explained on the connection.
1.2 Optional: Summarize other lesson content using conventional methods.

2. Written work

1. clone method

1.1 Write Employeea class in the test1 package, create a new class in the test2 package, and create a Testnew Employee object in the test1 package in its main, and then use the clone method to clone a new object. Can it be successful? Why?
1.2 If you want to override the clone method for a custom class, what should you pay attention to?
1.3 The methods in the Object object are toString, equals, hashCodeall decorated with public, but the clonemethods are decorated with protected. Please try to explain why. Why not declare it as public?

2. Inner class

2.1 Use anonymous classes and lambda expressions to rewrite the subject 7-2 of the object-oriented 2-advanced-polymorphic interface inner class . Please paste the key code and the running result, and your student ID and name will appear in the running result.
2.2. Analyze the following code and answer shapeComparatorwhat is the relationship between the pointed object and the Comparator interface?
Comparator<Shape> shapeComparator = new Comparator<Shape>() { @Override public int compare(Shape o1, Shape o2) { //你的代码 } };
2.3 Question set: 6-1 (anonymous inner class) experiment summary. What do you think are the benefits of using anonymous inner classes?

3. Summary of PTA experiments

3.1 PTA (custom interface). And answer: Compared with not writing an interface and directly writing a class with IntegerStackcorresponding methods, IntegerStackwhat are the benefits of defining an interface and then defining its implementation class?
3.2 PTA (static nested class). And answer: What is the difference between a static nested class and an inner class? In this question, what is the benefit of using static nested classes?
3.3 PTA (Inheritance Coverage Comprehensive Exercise - Person, Student, Employee, Company). And answer: Collections.sortWhat are the prerequisites for sorting an array of reference types?

4. Big job - continue to improve (try to use the interface to transform your system)

Refer to the Case-StudentDao.zip case.
Suppose that in different implementations, some of the items in the shopping cart are stored in ArrayList, and some are stored in arrays.
4.1 Now it is desirable to abstract the operation of the shopping cart in the system to the corresponding DAO interface, eg ShoppingCartDao.
4.2 Define at least two implementations for this interface (eg array, list, file). Take a screenshot of the key code of the part that you are responsible for, and require the name and student ID to appear .
4.3 Give your main function code and explain the benefits of defining the DAO interface.

5. Code reading: PersonTest.java (abstract, polymorphism, super)

5.1 Draw the inheritance relationship of the class
5.2 What function does the code of the main function achieve?
5.3 Is it OK to remove the super constructor in the subclass? Where does polymorphism manifest in
5.4 ? Reference link:PersonTest.java

PersonTest.java

3. Code cloud and PTA

Question set: jmu-Java-04-object-oriented 2-advanced-polymorphic interface inner class

3.1. Code cloud code submission record

  • In the code cloud project, select "Statistics-Commits History-Set Time Period", then search and take a screenshot

3.2 Screenshot PTA Question Set Completion Chart

Two graphs are required (1. Rank graph. 2. PTA submission list graph)

3.3 Count the amount of code completed this week

The weekly code statistics need to be merged into one table.

Source: https://shimo.im/doc/vzcXUa0OMFQtg24o?r=XZ047E

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325124859&siteId=291194637