Love Java,Love China!
when upcasting .....
1
//
codes start
2
class
base
{
//
a base class
3
4
//
constructor
5
public
base()
{
6
System.out.println(
"
base class construct
"
);
7
}
8
//
perform
9
public
void
perform()
{
10
System.out.println(
"
base class perform
"
);
11
}
12
//
destructor
13
public
void
finalize()
{
14
System.out.println(
"
base class destruct
"
);
15
}
16
}
17
18
19
class
subbase
extends
base
{
//
derive from base
20
21
//
constructor
22
public
subbase()
{
23
System.out.println(
"
sub class construct
"
);
24
}
25
//
perform
26
public
void
perform()
{
27
System.out.println(
"
sub class perform
"
);
28
}
29
//
destructor
30
public
void
finalize()
{
31
System.out.println(
"
sub class destruct
"
);
32
}
33
}
34
35
public
class
casting
{
//
test casting class
36
//
constructor
37
public
casting()
{
38
System.out.println(
"
begin casting test
"
);
39
}
40
41
public
static
void
main(String args[])
{
42
base father
=
new
base();
43
subbase son
=
new
subbase();
44
45
father.perform();
46
son.perform();
47
48
father
=
(base)son;
//
<1>
49
father.perform();
50
51
son
=
(subbase)father;
//
<2>
52
son.perform();
53
54
father
=
(base)((subbase)father);
//
<3>
55
father.perform();
56
}
57
}
58
59
//
codes end
60
Today ,when i go for a interview ,the project manager asked me this question !
Acturally ,It's just relate to the knowledge of reference && object !
Be carefull ,Nothing !
posted on 2008-05-25 19:40
devliu
阅读(107)
评论(0)
编辑
收藏
新用户注册
刷新评论列表
只有注册用户
登录
后才能发表评论。
网站导航:
博客园
IT新闻
Chat2DB
C++博客
博问
管理
<
2008年5月
>
日
一
二
三
四
五
六
27
28
29
30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
7
导航
BlogJava
首页
新随笔
联系
聚合
管理
统计
随笔 - 1
文章 - 0
评论 - 0
引用 - 0
常用链接
我的随笔
我的评论
我的参与
留言簿
(1)
给我留言
查看公开留言
查看私人留言
随笔档案
2008年5月 (1)
搜索
最新评论
Powered by:
BlogJava
Copyright © devliu