201521123109 Java programming Fourth week of study summary

Source: Internet
Author: User

1. Summary of this week's study

#1.1 Try to summarize the knowledge points about inheritance using the mind map.


#1.2 Use the general method to summarize other lessons.

-learned about the inheritance of classes

-Understand inheritance and polymorphism relationships and some keyword content

-Learned the Object-equals method, the Object-tostring method

2. Written work

#1. Application of annotations

Use the comments of the class and comments for the method to annotate the previously written classes and methods, and to view them in eclipse. ()

' A: Class comment

/**
....... What you want to comment on
/

`

#2. Object-oriented design (big job 1, very important)
# #2.1 will be in the online shopping mall or the class blog to learn the process, described as a story. (not less than 50 words, refer to the example of PPT in QQ Group)

' A: First of all we have to buy a Java book, in the Search box to enter "Java", and then I fancy the first book, click on the option to enter the book's details page, there is a series of information on the price, freight, quantity and so on, the item added to the shopping cart can see the quantity plus minus, the settlement button. `

`

C

# #2.2 Through this story, we can find out who is using this system, the system contains classes and their property methods, and the relationship between classes and classes. Try to find these classes and properties, and use mind maps to describe the relationships between classes, properties, methods, and classes.

# #2.3 Try to use Java code to implement the process described in the story (not very well), in the future to gradually improve on this basis, to expand into a complete object-oriented system. (Optional: Extra points)
Resources:
UML Class Diagram
Object-oriented case-borrower name address. zip

#3. Managertest.zip Code Analysis
Analyze the code in Managertest.zip and answer a few questions:
# #3.1 where is the use of inheritance for code reuse in this example? Which method, which property, should be specific to the answer.

' A: The two super keywords in these two codes, Getsalary () and constructor methods are all reused from the parent class. Property has name,salary,hireday. `
# #3.2 the Employee class and its subclass manager have getsalary methods, how do you differentiate between these two methods?

' A: Use the Super keyword method, or Java uses two Getsalary methods based on the specific type of object. `
# #3 The 26th line of the. 3 file E.getsalary () is the Getsalary method that invokes the manager class or the Getsalary method of the Employee class.

' A: Is the Getsalary method that invokes the manager class. `
# #3.4 The constructor of the manager class uses super to invoke the constructor of the parent class to implement code reuse, what do you think is the benefit of this? Why isn't it more intuitive to copy and paste the relevant code from the parent constructor into the manager's constructor?

' A: Using code reuse can simplify the code and improve the efficiency of the Code. `

#4. Object class
# #4.1 Write a fruit class and attribute string name, such as no extends from any class. Using System.out.println (New Fruit ()); What is the method of calling Fruit? Where did the code for the method come from? Trying to analyze what functionality this code implements?

' Answer: The ToString function of object is called, and the ToString () method comes from the object class. `
# #4.2 if the ToString () method is added for the Fruit class, then System.out.println (New Fruit ()) is used, and the new ToString method is called. So the code for the ToString method in its parent class is gone? If you want to reuse the ToString method of its parent class at the same time, how do I do it? (Demo with Code)

# #4.3 The Fruit class also inherits the Eqauls method of the object class. Trying to analyze its functionality? Write your own method of overriding the parent class with the Equals method, which returns true when the two fruit object name is the same (ignoring case). (use code to prove that the Eqauls method you covered is correct)

# #4.4 Use arraylist<fruit> fruitlist to store multiple Fruit on a 4.3 basis, requiring Fruit that are already in the fruitlist to no longer be added, without adding them. Please write the relevant test code. and analyze how ArrayList's Contatins method realizes its function?

#5. Code reading: Persontest.java (abstract, polymorphic)
# #5.1 to draw the inheritance relationship of a class

' Answer: '
# #5.2 Read the main function and compare the results of the code run with the actual running results. Try to analyze the reason

Secretary

Manager [bonus=12000.3, ToString () =employee [salary=90000.1, ToString () =person [Name=clark, Adress=ge, phonenumber= 111, [email protected], age=10, Gender=mail]]
Student [Status=1, ToString () =person [Name=wang, adress=110, phonenumber=15959, [email protected], age=18, Gender=male] ]
Employee [salary=1000.0, ToString () =person [Name=zhang, adress=136, phonenumber=1360, [email protected], age=21, gender =female]]
Programmer [allowance=50000.0, ToString () =employee [salary=100000.0, ToString () =person [Name=gates, Adress=usa, phonenumber=911, [email protected], age=59, Gender=male]]

Is that the subclass will also invoke the ToString () method of the parent class while outputting its own properties.

# #5.3 A super constructor is used inside subclasses, what is the function? If you remove the super constructor from the subclass, OK?

' A: In order to invoke the constructor of the parent class, if you remove the constructor that calls to the parent class, instead of calling the parent class's parameterless constructor automatically, you will get an error if there is no parameterless constructor in the parent class. `
# #5.4 Where does the code in Persontest.java show polymorphism? What do you think is the advantage of polymorphism? What is the relationship between polymorphism and inheritance?

' Answer: The following code shows polymorphism:

for (person Person:peoples) {
SYSTEM.OUT.PRINTLN (person);
}

The benefit of polymorphism is to avoid repeating too much code, and to output different results depending on the type of object calling the same method name. Polymorphism and inheritance the relationship between the parent class and the subclass because of inheritance, followed by the parent class and the child class, the subclass can invoke the parent class's method, and when the method name of the parent class is called and the method name in the subclass depends on the object type to determine which method is selected, the polymorphism is generated. `
Reference documents: Persontest.java

3. Code Cloud Codes Submission record

In the Code cloud Project, select statistics-commits history-set time period, and then search for and


#4. PTA Experiment

Topic set: jmu-java-03-Object-oriented 1-basic-encapsulation inheritance
function (4-1, 4-2, 4-3,4-4 more difficult to choose)
Programming (5-4, 5-5, 5-6)
Experiment Summary:

4.1 uses the Super keyword to simplify the code, saving time and space.

201521123109 Java programming Fourth week of study summary

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.