Week 7 learning summary

20172320 2017-2018-2 "Java Programming" seventh week study summary

Textbook learning content summary

1. Inheritance: Inheritance is one of the ways to support software reuse. It is faster, easier and less expensive than rewriting classes.
2. Inheritance establishes a "yes" relationship between the parent class and the subclass, that is, the subclass is a A more specific version of the parent class
3. Visibility modifier encapsulation public<protected<private
4. The reference of super can call the constructor of the parent class, and the super class constructor can only be executed in the subclass, and must be The first line executes
5. Java's inheritance method is single inheritance, and multiple inheritance is not supported.
6. Java has a class hierarchy, that is, a subclass of a class can be the parent class of one or more classes

Problems and Solving Processes in Teaching Materials Learning

  • Question 1: What is software reuse?
  • Problem 1 Solution: The book says that 继承是支持软件复用的途径之一it does not introduce what software reuse is. I found out by searching the internet for a blog about this that 软件复用是使用现有软件组件实现或更新软件系统的过程it can 降低成本和开发时间,产生可靠的软件,实现标准化,在不同应用中保持一致.
  • Question 2: The similarities and differences between super and this
  • Solution to problem 2: The book mentions that super is similar to this reference, but I don't feel the same in terms of usage, and the book doesn't propose any differences, so I searched the Internet.
  • Question 3: About abstract classes and abstract methods
  • Problem 3 Solution: Through a blog, I learned some differences between abstract classes and abstract methods
    抽象方法:在类中没有方法体的方法,就是抽象方法。 抽象类:含有抽象方法的类就叫抽象类。 抽象类中的抽象方法必须被实现! 如果一个子类没有实现父类中的抽象方法,则子类也成为了一个抽象类! 抽象类中的普通方法,可以不必实现。 用abstract来修饰一个类时,这个类叫做抽象类;用abstract来修饰一个方法时,该方法叫做抽象方法。 抽象类不能被实例化。 抽象方法只需声明,而不需实现某些功能含有抽象方法的类必须被声明为抽象类,抽象类必须被继承,抽象方法必须被重写。

Problems and solutions in code debugging

If there is a problem with the code debugging in the textbook, go to https://shimo.im/doc/1i1gldfsojIFH8Ip/ to see. If others have not asked the same question, you can edit the document to add it, and then copy your own question to the following:

  • Question 1: The result of PP9.1 only shows the sum of the denominations of coins, not the tossing result
  • Solution to problem 1: At the beginning, the array was defined like this.

    I thought everything was fine, and I didn't care. Later, I found that the output was missing, and then I directly System.out, but it still didn't work. After careful comparison, I found that I didn't use the method in Coin to throw, and naturally it didn't work. Because I defined an array, I can't X.flip(); X.isHead();. At first I didn't think that the definition was wrong, and I didn't find any problem after reading it over and over again. Later I remembered that this is an array, and I need to formulate a specific one to use flip and isHead to toss coins, so I changed it to this

code hosting


Summary of last week's exam mistakes

  • 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
    Analysis: The main method requires arguments in case the programmer wants 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.
  • 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
    Analysis : The length of the parameter can be changed, and the variable-length parameter is ...represented by the definition
  • 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
    analysis: ArrayList is implemented as an array, as long as one of them just accesses the elements of 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.
  • If x is a char, and values ​​is an int array, then values[x]
    A .causes a syntax error
    B .causes an Exception to be thrown
    C .casts x as an int based on x's position in the alphabet (for instance, if x is 'a' then it uses 0 and if x is 'z' then it uses 25)
    D .casts x as an int based on x's ASCII value (for instance, if x is 'a' then it uses 97 and if x is 'z' then it uses 122)
    E .casts x as an int based on the digit that is stored in x (for instance, if x is '3' it uses 3) but throws an exception if x does not store a digit
    analysis: The array index must be an int value, so normally the value [x] will cause a syntax error if x is not an int, but the Java compiler will automatically convert x to int if it can be converted. Characters are converted to type int by converting the char value to the equivalent ASCII value. So if x is 'a', it is converted to int 97, so value[x] accesses value[97].

    Pairing and mutual evaluation

  • 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 67/67 1/4 20/20
the second week 328/395 1/5 20/40
The third week 523/851 1/6 20/60
the fourth week 1070/1921 1/7 20/80
fifth week 608/2529 1/8 10/90
Week 6 608/2899 1/9 20/110
Week 7 429/3328 1/10 20/130

References

Guess you like

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