20172306 "Java programming and data structure" seventh week learning summary

20172306 "Java Programming" seventh week learning summary

Textbook learning content summary

这一章的标题是继承。主要学习了有关继承的相关知识。其中在这五节中,我学到了以下几点:
1.继承主要表达的是“是”这个关系。子类是父类的一个更具体的类。
2.我觉得这里要注意protected和public还有private之间的区别。当用protected时,子类可以引用父类的变量或方法,而且不破坏封装性。但是private就不可以引用。
3.对于super,我觉得也是一个很重要的点。super用来调用父类的构造方法。在继承中,我认为很重要,应该多了解一些。
4.重写方法和影子变量。在这里,书中说很容易混淆。我认为重写是指子类重新写和父类相同名称的方法。指的是方法。而影子变量,我觉得和重写的意义差不多,只不过它指的是变量之间的关系。
5.对于层次结构,我觉得就是将共用性强的类提高在较高的层次,这样引用的时候,更加的方便。同时,应知道Object类是没有父类的。
6.抽象类的知识,理解起来和接口差不多。注意如果抽象类的子类没有为每一个从父类继承的抽象方法提供定义,则该子类仍然是抽象类。
7.子类中不可以重写final方法。final类不能再用于派生新类。

Problems and Solving Processes in Teaching Materials Learning

  • Question 1: There is a sentence in the book: One of the purposes of inheritance is to reuse existing software. Which is not enough to understand the word reuse.
  • Problem 1 solution: ( https://wenwen.sogou.com/z/q811715400.htm )
    I went online to find out. In my understanding, reuse is to put some existing functions on new software. This has something to do with inheritance. Use some methods and variables of the parent class in the child class. This is similar to reuse.
  • Problem 2: While studying Chapter 9, I didn't know much about instantiation and initialization.
  • Solution to problem 2: I discussed it with my paired classmates and asked my classmates. Now I will talk about the difference between the two as I understand. Instantiation is generally an object created by a class, giving it a space when constructing an instance, but not giving it a specific value. But initialization is to give a variable a specific value. For Student stut = new Student(); this is instantiation; for int a = 2; this is initialization.
  • Question 3: For overridden content, want to know if subclass can override all methods of parent class.
  • Solution to problem 3: In the homework problems in the book, there is a problem, the problem is that a subclass can override the constructor in its parent class. This sentence is wrong. The explanation is this: a special method is constructed with the same name as the class, but with no return type. Attempting to override the superclass's constructor will result in a syntax error, since all methods except the constructor must have a return type.
  • Question 4: I don't understand what the book says, every class in a Java program inherits the toString method and the equals method?
  • Problem 4 solution: When I was thinking about this, I remembered that when we were doing experiment 4, we used equals as a method in the class. I read the interpretation of the book again, and I still didn’t understand it very well when I read it the first two times. When I read it again, I think it means this. When we write a class, if you use toString or equals, then these two methods It is copied from the Object class. This also shows that Object has no parent class.
  • Question 5: What is meant by abstract class does not necessarily contain abstract methods?
  • Solution to problem 5: I understand from the Internet that abstract classes can have no abstract methods, but if one of your classes has been declared as an abstract class, even if there are no abstract methods in this class, it cannot be instantiated again, that is, it cannot be directly constructed An object of this class. If a class has an abstract method, then the class must be declared as abstract, otherwise the compilation will fail. For abstract methods, you must use public abstract to decorate abstract methods, while private and protected cannot. If a class has abstract methods, then the class must be abstract.

    Problems and solutions in code debugging

  • Question 1:
    This is my test code for PP9.1. You will find that when I use n, the sum value it outputs is just my previous value, not the sum of all my previous values.

  • Solution to problem 1: I put the sum value in the while, run it for a while, and found that

    there was another problem before it succeeded. I used the while loop, but the infinite loop could not stop at all. I went to this question. A blog wrote about this problem, and then it was solved inexplicably. I know the problem this time, because when I wrote it again, I had created another variable. Later, when I used another, I created it. Another variable that caused my infinite loop to stop, no matter if I entered Y or n, it would not stop.

  • Question 2:
  • .Problem 2 solution:

code hosting

Summary of last week's exam mistakes

  • 1.The "off-by-one" error associated with arrays arises because
    A the first array index is 0 and programmers may start at index 1, or may use a loop that goes one index too far (array index is 0, programmers may start at index 1, or may use a loop that goes one index too far Can start at index 1, or use a loop that indexes too far.)
    B the last array index is at length + 1 and loops may only iterate to length, missing one Only iterate to length, one is missing)
    C the last array element ends at length - 1 and loops may go one too far (the last array element ends at length - 1 and loops may go one too far.)
    D programmers write a loop that goes from 0 to length - 1 whereas the array actually goes from 1 to
    length off-by-one" error has nothing to do with arrays

  • 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[ ]) 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? Define a parameter list for a method header?
    B (int a[ ])
    C (int[ ] a)
    D (int a)
    E (a[ ]) Choose C for this question

  • 3.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 implement. Then, the following instructions store the memory space.
    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 ( 1000 reference variables, each pointing to a bank account entry.)
    C a single BankAccount entry
    D 1000 BankAccount entries
    E 1000 reference variables and 1000 BankAccount entries First BankAccount[1000]; Instantiate BankAccount[] object for 1000 BankAccount objects. This means that First Empire Bank[0] and First Empire Bank[1] and First Empire Bank[999] are now legal references, each being a reference variable because each reference is A BankAccount object. Therefore, the statement reserves memory space for 1000 reference variables. Note that there is not one of these 1000 banks.

  • 4. Given the following declarations, which of the following variables are arrays?
    int[ ] a, b;
    int c, d[ ];
    A a
    B a and b
    C a and d
    D a, b and d
    E a, b, c and d This topic chooses D. His first statement declares that a and b are both int arrays. The second declaration declares that c and d are ints, but for d, an array of ints. ab and d are both int arrays.

  • 5.If a and b are both int arrays, then a = b; will
    A create an alias (create an alias)
    B copy all elements of b into a (copy all elements of b into a.)
    C copy the 0th element of b into the 0th element of a (returns true if each corresponding element of b is equal to the corresponding element of a (i.e. a[0] = b[0], a[1] = b[1], etc.) , otherwise returns false.)
    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 true if each corresponding element of b is equal to the corresponding element of a (i.e. a[0] = b[0], a[1] = b[1], etc.), otherwise Return false.
    E return true if a and b are aliases and return false otherwise If both variables are primitives, the variable on the left is a copy of the variable on the right (if a and b are int values, and b = 5, then it will become 5). However, because a and b are array references the variable is set to reference variable b, causing both a and b to reference the same array in memory, or they are now aliases of each other

  • 6.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. String is returned, and "\n" is inserted between each element.)
    A true
    B false This question chooses B

  • 7.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. (The Java main method uses parameters (String[] variables) so that the user can run the program and provide "command line" parameters. Since the parameter is an array of strings, the user does not have to provide any parameters.)
    A true
    B false A main method requires arguments in case the programmer wishes to allow the user to provide command line arguments. Anything entered on the command line after the java command will be accepted as a command line argument. If it is 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 variable[1] for use by the program.

  • 8.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.( As long as only the elements of the ArrayList are accessed, its efficiency is about the same as that of an array. It only deteriorates when one starts inserting or removing elements from the front part of the ArrayList.)
    A true
    B false The choice of A ArrayList is Implemented as an array, as long as one of them just accesses the elements of the ArrayList, the efficiency is the same as that of an array. However, when insertions or deletions are made to the front part of the ArrayList, a lot of element copying occurs, reducing its efficiency.

    Pairing and mutual evaluation

  • Worth learning or questions from the blog:

  • Worth learning or problems in the code:

  • Based on the scoring criteria, I rate this blog: 8 points.

    Reviewed classmates blog and code

  • Pair study this week
    • Learned some of the content of Chapter 9 together and practiced the example problems in the book.
    • We are in this together when writing PP assignments. I made it up a bit earlier than he did, so when there was a problem, we solved it together.
    • When I was reading a book together, I discussed about instantiation and initialization, and then he told me the difference between the two. I think he has made a lot of progress than before.
  • Last week's mutual comment on blogs
    Last week's mutual comment, I think what he said is very reasonable, and the problem he said is indeed what I personally think is my inadequacy. I am correcting this blog.

Others (perception, thinking, etc., optional)

 这周学习了继承的内容,我觉得总体上,这周学习的时间还算多,这样的学习进度是可以接受的,对于例题的学习比前几周仔细些。而且,在自己编写的过程中,明显比前几次更有思路了,知道自己想表达什么,应该表达出什么了。这是我这周的收获。之前的学习可能因为不够仔细和扎实,有一些很基础的东西,很容易忘记,所以以后打算慢慢地把之前的内容仔细再看一看,可能在接下来的编程中会更加的容易。

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 193/200 1/1 20/20
the second week 247/440 1/1 22/42
The third week 445/895 2/2 20/62
the fourth week 885/1780 1/1 43/105
fifth week 775/2555 1/1 55 /160
Week 6 1171/3726 1/1 38/198
Week 7 596/4322 1/1 60/258

References

Guess you like

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