Java开发网 |
注册 |
登录 |
帮助 |
搜索 |
排行榜 |
发帖统计
|
您没有登录 |
» Java开发网 » Java SE 综合讨论区
打印话题 寄给朋友 订阅主题 |
作者 | Re:Good Example. Plz, give me one point [Re:floater] |
jam
发贴: 79 积分: 30 |
于 2003-04-11 09:35
class A { int i = 1; int f() { return i; } static char g() { return 'A'; } } class B extends A { int i = 2; int f() { return -1; } static char g() { return 'B'; } } public class Test { public static void main(String args[]) { B b = new B(); System.out.println(b.i); // 2 System.out.println(b.f()); // -2 System.out.println(b.g()); // B System.out.println(B.g()); // B A a = (A) b; System.out.println(a.i); // 1 // **************** System.out.println(a.f()); // -2 // **************** System.out.println(a.g()); // A System.out.println(A.g()); // A } } Sorry, I come from Taiwan, I can not post encoding by "GB2312" or "HZ" The system will be using "Big5" The exmaple is in "Java in a nutshell". The chinese version is in "chapter 3" java object orient. About subclass and inheritance, over write the method of super class. I think it can be explain by "Polymorphism" 如何用JTable设置表头多行 |
话题树型展开 |
已读帖子 新的帖子 被删除的帖子 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |