20172313 2017-2018-2 "Program Design and Data Structure" Week 7 Learning Summary

20172313 2017-2018-2 "Program Design and Data Structure" Week 7 Learning Summary

Textbook learning content summary

  1. Learned how to create a subclass.
  2. Learned to use the protected modifier to allow subclasses to access a public variable of the parent class and use the reserved word super to call the constructor of the parent class.
  3. Learned how to override the method of the parent class.
  4. Preliminary study of class hierarchy, understanding of Object class and abstract class and interface hierarchy.
  5. Learned how a subclass can reference methods and variables and constants in the parent class through an additional method.
  6. Preliminary study of the design of the inheritance relationship between classes.

Problems and Solving Processes in Teaching Materials Learning

  • Question 1: When learning interfaces, there is such a question, what is the difference between interfaces and abstract classes and how to use them. Now that I have read this chapter, I want to figure it out and record it here for future review.
  • Problem 1 solution:

    In terms of syntax: abstract class
    1. A class modified by the abstract keyword is called an abstract class.
    2. A method that is not implemented in an abstract class is called an abstract method, and the keyword abstract is also required.
    3. There can be no abstract methods in abstract classes, such as HttpServlet methods.
    4. An abstract class can have implemented methods and define member variables.
    Interface
    1. Modified by the interface keyword is called an interface;
    2. Member variables can be defined in the interface, but these member variables are public static final constants by default.
    3. There are no implemented methods in the interface, all are abstract methods.
    4. A class that implements an interface must implement all the methods defined in the interface.
    5. A class can implement multiple interfaces.

  • To put it simply, an interface is public, and cannot have private methods or variables in it. It is for others to use, while an abstract class can have private methods or private variables. In addition, those who implement an interface must implement the definitions in the interface. In general, the top level is the interface, then the abstract class implements the interface, and finally the concrete class implements. Also, interfaces can implement multiple inheritance, and a class can only inherit one superclass, but multiple inheritance can be achieved by inheriting multiple interfaces. The interface also has an identity (there is no method in it, such as the Remote interface) and data sharing (inside the interface). variables are all constants). In addition, there are differences at the design level. Due to the lack of knowledge, it has not been cited here. A link is attached at the end of this blog for future viewing.
  • Question 2: When I first read the textbook, I saw this: Under normal circumstances, the first line of the constructor should use super reference to call the parent class constructor. If no such call exists, Java automatically generates a line of super() calls at the very beginning of the constructor. I don't understand what this sentence is trying to convey.
  • Solution to problem 2: I also encountered such a problem when doing exercises. The problems in the following code debugging are reflected, and I gradually understand and experience it in the writing and practice of the code.
  • Question 3: When I first started learning, I thought that the subclass could directly call all the methods and variables in the parent class, but later I found out that it was wrong. When I read Example 9_12, my thoughts were more affirmed.
  • Problem 3 solution:
  1. About private member variables
    Whether the member variables in the parent class are private, public, or other types, the child class will have these member variables in the parent class. However, private member variables in the parent class cannot be directly accessed in the subclass, and must be accessed through protected and public methods (such as getter and setter methods) inherited from the parent class.
  2. About static member variables
    Whether the member variables in the parent class are static or non-static, the child class will have these member variables in the parent class.
  3. About member variables overridden by
    subclasses Whether the member variables in the parent class are overridden by the subclass, the subclass will have these member variables in the parent class.

Problems and solutions in code debugging

  • Question 1: When doing homework exercise 9_1, the compilation fails, and it prompts me that I need an identifier.

  • Solution to problem 1: I think there should be a problem with the syntax of my line of code, so I modified it to the following format.

  • Question 2: I didn't understand the reserved word super well at that time. I didn't understand that the super reference should be used in the first line of the subclass's construction method. After modifying the code again, there was no problem. ヽ( ̄▽ ̄)ノ
  • Problem 2 solution:

code hosting

Summary of last week's exam mistakes

  • 错题1: In Java, rrays are
    A . primitive data types
    B . objects
    C . interfaces
    D . primitive data types if the type stored in the array is a primitive data type and objects if the type stored in the array is an object
    E . Strings
  • Parsing In Java, arrays are implemented as objects. This variable is a reference variable to the block of memory that stores the entire array. However, the array is accessed using the token name [index] instead of message passing.
  • Reason: This question is still unclear about the specific concept of arrays when learning...
  • 错题2: If an int array is passed as a parameter to a method, which of the following would adequately define the parameter list for the method header?
    A . (int[ ])
    B . (int a[ ])
    C . (int[ ] a)
    D . (int a)
    E . (a[ ])
  • Resolution The parameter is defined as the variable was originally declared, the type parameter name. Here the type is int[] and the parameter is a.
  • Reason: This question is negligent, and the wrong choice was accidentally made.
  • 错题3: If a and b are both int arrays, then a = b; will
    A . create an alias
    B . copy all elements of b into a
    C . copy the 0th element of b into the 0th element of a
    D . return true if each corresponding element of b is equal to each corresponding element of a (that is, a[0] is equal to b[0], a[1] is equal to b[1] and so forth) and return false otherwise
    E . return true if a and b are aliases and return false otherwise
  • Parsing "=" is an assignment operator. If both variables are primitives, then the variable on the left gets a copy of the variable on the right (so if a and b are int values ​​and b = 5, then a becomes 5). However, since a and b are arrays, the reference variable a is set to reference the variable b, causing a and b to reference the same array in memory, or they are now aliases to each other.
  • Reason: The content in the book is not fully understood.
  • Mistake 4: In Java, an array can only store one type of data. For instance, you cannot create an array that stores both double and String values.
    A . true
    B . false
    Resolution Arrays are said to be of the same type. This means that the type of the value stored in the array must be the same for each element. The type is determined by the declaration. So, int[]x just makes x an array of ints. So, no array can store doubles and strings.
  • Reason: When studying the textbook, the variable parameter length was misunderstood as being able to store different types of values ​​at the same time.
  • 错题5: Just as arrays can only have a fixed number of elements, set at the time the array is declared, a parameter list also can only have a fixed number of elements, set at the time the method is declared.
    A . true
    B . false
  • Parsing Java provides special notation for variable-length parameter lists. An ellipsis (...) is used to specify a variable-length parameter list.
  • **Cause: Variable length parameter comprehension confusion.

Pairing and mutual evaluation

Review Template:

  • Worth learning or questions from the blog:
    • The layout is beautiful, the research is very detailed, and the answers are very comprehensive.
  • Worth learning or problems in the code:
    • The code is well written and the thinking is clear, keep going!

Reviewed classmates blog and code

  • Pair study this week
    • 20172332
    • Pair learning content
      • Chapter 9 Inheritance

other

The content of this week is not that difficult from my own feeling, and it is not as difficult to study as in the previous weeks, but because there are still experimental classes this week, the learning task is not light, but it is good to learn the teaching materials. There is no trouble with the content, and there are no major problems when debugging the code. Hope to continue to work hard in the future study and continue to make progress!

learning progress bar

Lines of code (added/accumulated) Blog volume (new/cumulative) Study time (added/accumulated) important growth
Target 5000 lines 30 articles 400 hours
the first week 126 1/1 20/20
the second week 388/466 1/2 15/35
The third week 706/1162 1/3 17/52
the fourth week 1104/2266 1/4 20/72
fifth week 1126/3392 1/5 15/87
Week 6 906/4298 1/6 20/107
Week 7 1233/5531 1/7 20/127
  • Planned study time: 20 hours

  • Actual study time: 20 hours

  • Improvement:
    Compared with other students' learning situation, I really feel ashamed and feel that my learning is not enough. I hope to continue to work hard in the future study and life, learn more Java, code more, and learn more.To the peak of life!

References

Guess you like

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