201521044091 Java Programming 5th Week of study summary

Source: Internet
Author: User
Tags comparable

1. This week's study summary 1.1 attempts to summarize knowledge points about polymorphism and interfaces using mind mapping.

1.2 Optional: Summarize other lessons using the usual methods. Interfaces can define behavior, but they cannot define operations;the abstract method modifies methods that may change. 2. Written work 1.1 com.parent package Child.java file can be compiled through? Which sentence will be wrong? Try to correct the error. and analyze the output results.
Package parent;PublicClassoutofparentpackage{PublicStaticvoidSHOWPARENTJ (Parent p) {System.Out.println (P.J); System.Out.println (P.geti ()); P.GETJ (); }}Classparent{Privateint i=1;Protectedint j=2;ProtectedIntGeti (){return i; }PublicvoidGETJ () {System.Out.println (j); }}Classother{PublicStaticvoidSHOWPARENTJ (Parent p) {System.Out.println (P.J); System.Out.println (P.geti ()); } }PublicClassChildExtendsparent{PublicStaticvoid main (String[] args) {Parent p = Span class= "Hljs-keyword" >new Parent (); Child C = new Child (); C.getparenti (); C.getparentj (); OTHER.SHOWPARENTJ (P); } public void getparenti ( Out.println (i); } public void GETPARENTJ ( Out.println (SUPER.J); System. out.println (j); System. out.println (Geti ()); System. out.println (Super.geti ());}          

The output result is

1.2 Outofparentpackage.java In another package, can the compiler pass? What errors are prompted? Analyze the cause. How can I change it to make it compile properly? (It doesn't matter if you can't write the correct answer, but be sure to write the thinking process.)
(2) Abstract Advanced: Reading Guessgame abstract class design and use of source code 2.1 guess the pre-transformation code is simple, and the modified code uses abstract classes, abstract methods look very complex, then what is the benefit of such a transformation?
2.2 What should I do if I want to transform this game into a graphical interface?
2.3 Combining This example, when do you think you should use abstract?
2.4 Important: In this case, what is the change and what is the same? Attempt to combine abstract, inheritance and other concepts to illustrate.
(3) Comparable and Comparator3.1 describe the purpose of the comparable interface. Why does a class implement the comparable interface so that it can be sorted directly using Arrays.sort?

3.2 Why do I need a comparator interface with the comparable interface?
(4) interface-oriented case analysis, read Case-studentdao.zip case 4.1 draw a class diagram describing the role of each class and interface.

答:Student是一个包含名字属性的类。StudentDao接口中包含writeStudent和readStudent以及diplayAllStudent方法。StudentDaoArrayImpl是对StudentDao接口的操作,其中定义了方法Student readStudent(String name) 和boolean writeStudent(Student student) 以及void diplayAllStudent()。StudenDaoListImpl是对StudentDao接口的另一个操作,也包含了对方法Student readStudent(String name) 和boolean writeStudent(Student student) 以及void diplayAllStudent()的定义。
What is the difference between 4.2 Studendaolistimpl and Studentdaoarrayimpl?
(5) What is interface-oriented programming? What are the benefits of interface-oriented programming? Discuss the analysis in conjunction with topic 3 and 4 (Test.java code). Do not copy Baidu intact! 答:题目3种采用Comparable和Comparator接口,调用Arrays.sort方法实现排序;Comparable定义在类的内部,Comparator定义在类的外部。
      • Benefits: Can make code logic clear, code understandable, easy to expand, maintainability strong;
        Interface similar function, we just write the function well, do not care who want to use, this can improve efficiency, later according to the specific requirements implements this interface is good.
3.1. Code Cloud codes Submission record

3.2. PTA experiments require a deep understanding of the concept and definition of interfaces. Experimentation is not easy, and it takes a lot of data to get it done.

201521044091 Java Programming 5th 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.