Java课件第三章_第1页
Java课件第三章_第2页
Java课件第三章_第3页
Java课件第三章_第4页
Java课件第三章_第5页
已阅读5页,还剩106页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、12345678910111213141516171819 2021 p p u u b b l l i i c c c c l l a a s s s s c c 1 1 p p u u b b l l i i c c i i n n t t x x ; ; i i n n t t y y ; ; p p r r i i v v a a t t e e i i n n t t z z ; ; p p u u b b l l i i c c v v o o i i d d m m 1 1 ( ( ) ) v v o o i i d d m m 2 2 ( ( ) ) p p r r i i v

2、 v a a t t e e v v o o i i d d m m 3 3 ( ( ) ) p p u u b b l l i i c c c c l l a a s s s s c c 2 2 c c 1 1 o o = = n n e e w w c c 1 1 ( ( ) ) ; ; c c a a n n a a c c c c e e s s s s o o . . x x ; ; c c a a n n a a c c c c e e s s s s o o . . y y ; ; c c a a n n n n o o t t a a c c c c e e s s s s o

3、 o . . z z ; ; c c a a n n i i n n v v o o k k e e o o . . m m 1 1 ( ( ) ) ; ; c c a a n n i i n n v v o o k k e e o o . . m m 2 2 ( ( ) ) ; ; c c a a n n n n o o t t i i n n v v o o k k e e o o . . m m 3 3 ( ( ) ) ; ; p p a ac ck ka ag ge e p p 1 1; ; p p a ac ck ka ag ge e p p 2 2; ; p p u u b b l

4、 l i i c c c c l l a a s s s s c c 3 3 c c 1 1 o o = = n n e e w w c c 1 1 ( ( ) ) ; ; c c a a n n a a c c c c e e s s s s o o . . x x ; ; c c a a n n n n o o t t a a c c c c e e s s s s o o . . y y ; ; c c a a n n n n o o t t a a c c c c e e s s s s o o . . z z ; ; c c a a n n i i n n v v o o k k e

5、 e o o . . m m 1 1 ( ( ) ) ; ; c c a a n n n n o o t t i i n n v v o o k k e e o o . . m m 2 2 ( ( ) ) ; ; c c a a n n n n o o t t i i n n v v o o k k e e o o . . m m 3 3 ( ( ) ) ; ; 2223 2425262728293031323334/ before constructor/ re-initialize t3/ after constructor/ at end/ shows that construction

6、 is done353637383940414243444546flower(int petals)flower(int petals)flower(string ss)flower(string ss)flower(string s, int petals)flower(string s, int petals)/! this(s); / cant call two!/! this(s); / cant call two!flower()flower()/! this(11); / not inside non-constructor!/! this(11); / not inside no

7、n-constructor!47484950515253545556575859606162636465class a void b(int x) void b(int i) class a void b(integer x) void b(int i) class a void b( ) void b(int i) class a void b(int x,int j) void b(int i) 66class a int b(int a, int j) int b(int j,int a) class a boolean t; void b(boolean t ) void b(bool

8、ean s) class a int b(int j, char a) int b(char j, int a)class a int b(int a) boolean b(int j) 6768697071727374class super public int i=0; public super(string text) i=1;public class sub extends super public sub(string text) i=2; public static void main(string ag) sub sub=new sub(“hello”); system.out.

9、println(sub.i); 75子类调用构造方法前子类调用构造方法前,缺省调用无参的缺省调用无参的, 为为保证继承链上的连续保证继承链上的连续性性,添加一个无参的添加一个无参的public b( ) 7677787980818283848586878889909192public class test public static void main(string args) m(new graduatestudent(); m(new student(); m(new person(); m(new object(); public static void m(object x) syst

10、em.out.println(x.tostring(); class graduatestudent extends student class student extends person public string tostring() return student; class person extends object public string tostring() return person; 93 dynamic binding works as follows: suppose an object o is an instance of classes c1, c2, ., c

11、n-1, and cn, where c1 is a subclass of c2, c2 is a subclass of c3, ., and cn-1 is a subclass of cn. that is, cn is the most general class, and c1 is the most specific class. in java, cn is the object class. if o invokes a method p, the jvm searches the implementation for the method p in c1, c2, ., c

12、n-1 and cn, in this order, until it is found. once an implementation is found, the search stops and the first-found implementation is invoked. cn cn-1 . . . . . c2 c1 object since o is an instance of c1, o is also an instance of c2, c3, , cn-1, and cn 94 . 9596979899/! final value v4; / pre-java 1.1 error; no

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论