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

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

Textbook learning content summary

  • Inheritance, the process of deriving a new class from an existing class, is a prominent process of object-oriented programming.
  • Subclasses and superclasses can be seen as a "yes" relationship.
  • Protected encapsulation is not as strict as private, but it is more visible than public.
  • super allows subclasses to use the superclass's constructor.
  • Java can implement multiple inheritance with methods of interfaces.
  • Subclasses can override superclass methods.
  • In principle shadow variables should be avoided.
  • final can limit inheritance

Problems and Solving Processes in Teaching Materials Learning

  • Question 1: I don't know what super reference can refer to.
  • Solution to problem 1: Query data to know that super has three uses: 1. Ordinary direct reference. Similar to this, super is equivalent to pointing to the parent class of the current object, so you can use super.xxx to refer to the members of the parent class. 2. The member variable or method in the subclass has the same name as the member variable or method in the parent class. 3. Reference the constructor. References
  • Problem 2: Don't understand the class content of the class hierarchy
  • Solution to Problem 2: Prepare to wait for the teacher to explain in class
  • Question 3: I don't know much about how to implement multiple inheritance
  • Solution to problem 3: Multiple inheritance can be achieved through interfaces and inner classes. References

    Problems and solutions in code debugging

  • Problem 1: An error occurs when using return to return the value
  • Solution to problem 1: mistakenly added "=" between return and the value to be returned

  • Problem 2: Sometimes when writing code, dropping a "{" or "}" leads to a lot of errors...
  • Solution to problem 2: Only be careful when writing, and check carefully after writing

code hosting

(screenshot of the running result of the statistics.sh script)

Summary of last week's exam mistakes

  • 错题1及原因,理解情况
    Assume that BankAccount is a predefined class and that the declaration BankAccount[ ] firstEmpireBank; has already been performed. Then the following instruction reserves memory space for
    firstEmpireBank = new BankAccount[1000];
    A . a reference variable to the memory that stores all 1000 BankAccount entries
    B . 1000 reference variables, each of which point to a single BankAccount entry
    C . a single BankAccount entry
    D . 1000 BankAccount entries
    E . 1000 reference variables and 1000 BankAccount entries
    正确答案: B
    你的答案: A
    declare BankAccount[] firstEmpireBank; Reserve memory space for firstEmpireBank, which itself is a reference variable pointing to the BankAccount[] object. Declare firstEmpireBank = new BankAccount[1000]; Instantiate the BankAccount[] object as 1000 BankAccount objects. This means that firstEmpireBank[0] and firstEmpireBank[1] and firstEmpireBank[999] are now valid references, and each reference variable is a reference variable, as each references a BankAccount object. So, this statement reserves memory space for 1000 reference variables. Note that none of the 1000 BankAccount objects have been instantiated, so no memory has been set aside for any actual BankAccount objects.
  • Wrong question 2 and the reason, understand the situation
    Arrays have a built in toString method that returns all of the elements in the array as one String with "\n" inserted between each element.
    A . true
    B . false
    Correct answer: B
    your answer : A
    arrays are objects, so they inherit from the Object class. The Object class has a toString method. However, Object's toString method does not return the value stored in Object, but the value of the reference variable. So, toString used on an array doesn't return the value stored in the array, it returns a nonsense set of characters.
  • Wrong question 3 and reasons, understand the situation
    A Java main method uses the parameter (String[ ] variable) so that a user can run the program and supply "command-line" parameters. Since the parameter is a String array, however, the user does not have to supply any parameters.
    A . true
    B . false
    Correct Answer: A
    Your answer: B The
    main method requires parameters in case the programmer wants to allow the user to supply command line parameters. Then, anything entered on the command line is accepted as a command line argument. If it's several words separated by spaces, then each word is stored as a separate string array element. For example, "java foo.class hi there" will store "hi" in variable[0] and "there" in variable[1] for program use.
  • Wrong question 4 and reasons, understand the situation
    An array index cannot be a float, double, boolean or String.
    A . true
    B . false
    Correct answer: A
    Your answer: B
    array index must be of type int, or can be extended to int value (so char, byte and short are also allowed).
  • Wrong question 5 and reasons, understand the situation
    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
    Correct answer: A
    your answer : B
    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.
  • Wrong question 6 and reasons, understand the situation
    So long as one is only accessing the elements of an ArrayList, its efficiency is about the same as that of an array. It's only when one begins to insert or remove elements towards the front portion of an ArrayList that its efficiency deteriorates.
    A . true
    B . false
    Correct Answer: A
    Your answer: B
    ArrayLists are implemented as arrays, so as long as the elements of an ArrayList are accessed, their efficiency is about the same as an array. However, its efficiency must be reduced when insertions or deletions are made to the front part of the ArrayList, i.e. when a large number of elements are copied.

Pairing and mutual evaluation

Review Template:

  • Worth learning or questions from the blog:
    • xxx
    • xxx
    • ...
  • Worth learning or problems in the code:
    • xxx
    • xxx
    • ...
  • Based on the scoring criteria, I give this blog a score: XX points. The scores are as follows: xxx

  • Reference example

Reviewed classmates blog and code

  • Pair study this week
    • 20172318
    • Pair learning content
      • Discussed about this week's experiment
  • Last week's blog comments

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 200/200 2/2 20/20
the second week 287/481 2/4 18/38
The third week 320/801 3/7 22/60
the fourth week 900/1600 2/9 30/90
fifth week 807/2407 2/11 40/130
Week 6 619/3023 2/13 40/170
Week 7 621/3644 2/15 40/210

References

Guess you like

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