20145321 Java Programming 4th Week of study summary

Source: Internet
Author: User

20145321 "Java Program Design" 4th Week study summary textbook study content summary sixth chapter inheritance and polymorphism

6.1 What is inheritance

 1、继承共同行为: 继承基本上就是避免多个类间重复定义的行为。 Pull Up————可以把相同的程序代码提升为父类。 extends关键字————表示新建的类会扩充原有的类的行为。 2、多态与is-a: 子类只能继承一个父类,并且子类与父类之间有一种is-a的关系,让不是一种的类扮演另一种类需要加上类似 于强制类型转换的语法。 什么叫多态?抽象的解释就是使用单一接口操作多种类型的对象。 3、重行定义行为: 在继承父类之后,定义与父类中相同的方法部署,但执行内容不同,这称为重新定义(Override)。 在重新定义父类中某个方法的时候,子类必须撰写与父类方法中相同的签署。 如果要重新定义某方法,加上@Override就不用担心打错字的问题。 4、抽象方法、抽象类: 如果某方法区块中真的没有任何程序代码操作,可以使用abstract标示该方法为抽象方法。 子类如果继承抽象类,对于抽象方法有两种做法,一是继续标示该方法为abstract,二是操作抽象方法。

6.2 Inheritance Syntax Details

 1、protected成员: 被声明为protected的成员,相同包中的类可以直接存取,不同包中的类可以在继承后的子类直接存取。 2、重新定义的细节: super关键字————在调用方法前加上super,可以取得父类中的方法定义。 重新定义方法要注意,对于父类中的方法权限,只能扩大但不能缩小。 3、再看构造函数: 创建子类实例后,会先执行父类构造函数定义的流程,再执行子类构造函数定义的流程。 父类中可重载多个构造函数,若子类构造函数中无指定执行父类哪个构造函数,默认调用父类中无参构造函数。 4、再看final关键字: 如果class前使用final关键字,表示这个类是最后一个,不会再有子类,也就是不能被继承。 5、java.lang.Object: 如果定义类时没有使用extends关键字指定继承任何类,那一定是继承java.lang.Object。 6、关于垃圾收集: 无法通过变量参考的对象被视为垃圾对象被JVM的垃圾收集机制处理。
Seventh chapter interface and polymorphism

7.1 What is an interface

 1、接口定义行为: 对于“定义行为”,可以使用interace关键字定义。 类要操作接口,必须使用implements关键字。 操作某接口时,对接口中定义的方法有两种处理方式,一是操作接口中定义的方法,二是再度将该方法表示为 abstract。 2、行为的多态: 只要是操作同一个接口的对象,都可以使用同一方法(行为)。 3、解决需求变化: 在java中,类可以操作两个以上的类,也就是拥有两种以上的行为。 在java中,接口可以继承自另一个接口,也就是继承父接口行为,再在子接口中额外定义行为。

7.2 Interface Syntax Details

 1、接口的默认: 接口中的方法没有操作时,一定得是公开并且抽象。 2、匿名内部类: 临时继承某个类或操作某个接口并建立实例,由于只使用一次,不需要为这些类定义名称,这时可以用匿名内部 类(Anonymous Inner Class)。 3、使用enum枚举常数: enum定义了特殊的类,继承自java.lang.Enum,可用于定义枚举常数。
Problems in teaching materials learning and the solving process

This week's inheritance made me feel very interesting, perhaps because the author used the code of the design game to arouse my interest. But the code also become more and more long, complex difficult code, in the code is always wrong, the content too much to see Dizzy, to the seventh chapter is not how to look down.

Problems in code debugging and the resolution process

It's all about the code on the book, and it's not too much of a problem. Here only the managed directory, specifically on Git hosting view.

Learning progress Bar

/Cumulative) new/cumulative)
lines of code (newBlog volume (Learning time (new/cumulative) Important growth
Goal 3500 rows 28 Articles 300 hours
First week 150/150 1/2 20/20
Second week 150/250 1/3 20/40
Third week 150/300 1/4 20/60
Week Four 250/500 1/5 20/80

20145321 Java Programming 4th 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.