• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
wangchunmei
博客园 首页 新随笔 联系 订阅 订阅 管理

2013年4月14日

继承和多态(Example5_9)
摘要: class Animal{ void cry(){}}class Dog extends Animal{void cry(){ System.out.println("wang!wang!......");}}class Cat extends Animal{ void cry(){System.out.println("miao~~miao~~...");}}public class Example5_9{public static void main(String arg[]){Animal animal; animal=new Dog(); ani 阅读全文
posted @ 2013-04-14 18:50 wangchunmei 阅读(144) 评论(0) 推荐(0)
 
对象的上转型对象(Example5_8)
摘要: class A{ double n; int m;void f(){ System.out.printf("子类继承方法f(),n=%f,m=%d\n",n,m);}void g(){ System.out.printf("你好,n=%f,m=%d\n",n,m);}}class B extends A{int n=12; void g(){System.out.printf("子类重写方法g(),n=%d,m=%d\n",n,m);}void cry(){System.out.printf("子类新增的方法,n=%d,m= 阅读全文
posted @ 2013-04-14 18:47 wangchunmei 阅读(164) 评论(0) 推荐(0)
 
关键字super
摘要: class A{int x,y;A(){x=100;y=200;}A(int x,int y){this.x=x;this.y=y;}}class B extends A{int z;B(int x,int y){super(x,y);z=300;}B(){super();z=800;}public void f(){System.out.printf("x=%d,y=%d,z=%d\n",x,y,z);}}public class Example5_6{public static void main(String arg[]){B b1=new B(10,20);b1.f 阅读全文
posted @ 2013-04-14 18:36 wangchunmei 阅读(140) 评论(0) 推荐(0)
 
成员变量的隐藏和方法重写(Example5_3/Example5_4/Example5_5)
摘要: class A{public double y=11.456789;public void f(){y=y+1;System.out.printf("y是double型的变量,y=%f\n",y);}}class B extends A{int y=0;public void g(){y=y+100;System.out.printf("y是int型的变量,y=%d\n",y);}}public class Example5_3{public static void main(String arg[]){B b=new B();b.y=200;b.g() 阅读全文
posted @ 2013-04-14 18:34 wangchunmei 阅读(253) 评论(0) 推荐(0)
 
Example5_2(子类对象的构造方法)
摘要: class A{private int x=10;protected int y=20;void f(){y=y+x;System.out.printf("x=%d,y=%d\n",x,y);}}class B extends A{void g(){y=y+1;System.out.printf("y=%d\n",y);}}public class Example5_2{public static void main(String arg[]){B b=new B();b.g();b.f();b.g();}} 阅读全文
posted @ 2013-04-14 18:30 wangchunmei 阅读(152) 评论(0) 推荐(0)
 
字符数组中的大小写字母变换/使用对象数组
摘要: public class Example4_18{public static void main (String arg[]){char a[]={'a','b','c','D','E','F'};for(int i=0;i<a.length;i++){if(Character.isLowerCase(a[i])){a[i]=Character.toUpperCase(a[i]);}else if(Character.isUpperCase(a[i])){a[i]=Character.toLo 阅读全文
posted @ 2013-04-14 18:24 wangchunmei 阅读(458) 评论(0) 推荐(0)
 
 

公告


博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3