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

2013年6月22日

Runnablej接口
摘要: public class Example8_4{public static void main(String arg[]){Left targetOfLeft=new Left();Thread left=new Thread(targetOfLeft);Right targetOfRight=new Right();Thread right=new Thread(targetOfRight);left.start();right.start();while(true){if(targetOfLeft.n==8||targetOfRight.n==8)System.exil(0);}}}cla 阅读全文
posted @ 2013-06-22 11:10 wangchunmei 阅读(174) 评论(0) 推荐(0)
 
Thread的子类创建线程
摘要: public class Example8_3{public static void main(String arg[]){Left left=new Left();Right right=new Right();left.start();right.start();while(true){if(left.n==8||right.n==8)System.exit(0);}} }class Left extends Thread{int n=0;public void run(){while (true){n++;System.out.printf("\n%s"," 阅读全文
posted @ 2013-06-22 10:51 wangchunmei 阅读(220) 评论(0) 推荐(0)
 
 

2013年4月25日

字符常量和变量的区别
摘要: class A{public void test(){int a=10; int b=20; System.out.println('a'); System.out.println('b'); System.out.println(a); System.out.println(b);}}public class ZiFu{public static void main(String arg[]){A a=new A();a.test();}} 阅读全文
posted @ 2013-04-25 21:40 wangchunmei 阅读(291) 评论(0) 推荐(0)
 
抽象类,并且有3 个抽象方法
摘要: abstract class Math{public abstract void f(int x);public abstract void g(int x,int y);public abstract double h(double x);}class Cheng extends Math{int x=10;int y=10;public void f(int x){System.out.println("我爱乘法");System.out.printf("x=%d",x);}public void g(int x,int y){System.out. 阅读全文
posted @ 2013-04-25 17:13 wangchunmei 阅读(215) 评论(0) 推荐(0)
 
 

2013年4月24日

异常类(Example5_18/Example5_19)
摘要: public class Example5_18{public static void main(String arg[]){int n=0,m=0,t=0;try{t=9999;m=Integer.parseInt("8888");n=Integer.parseInt("12s3a");System.out.println("我没有机会输出");}catch(Exception e){System.out.println("发生异常");n=123;}System.out.println("n=&quo 阅读全文
posted @ 2013-04-24 17:43 wangchunmei 阅读(205) 评论(0) 推荐(0)
 
 

2013年4月21日

匿名类
摘要: abstract class Student{abstract void speak();}class Teacher{void look(Student stu){stu.speak();}}public class Example5_16{public static void main(String arg[]){Teacher zhang=new Teacher();zhang.look(new Student(){void speak(){System.out.println("这是匿名类中的方法");}});}}interface Show{public void 阅读全文
posted @ 2013-04-21 22:02 wangchunmei 阅读(178) 评论(0) 推荐(0)
 
接口回调(接口回调和接口作为参数)
摘要: interface ShowMessage{void showTradeMark();}class TV implements ShowMessage{public void showTradeMark(){System.out.println("我是电视机");}}class PC implements ShowMessage{public void showTradeMark(){System.out.println("我是电脑");}}public class Example5_12{public static void main(String a 阅读全文
posted @ 2013-04-21 21:36 wangchunmei 阅读(395) 评论(0) 推荐(0)
 
类实现接口(Example5_11)
摘要: interface Computable{final int MAX=100;int f(int x);public abstract int g(int x,int y);}class A implements Computable{public int f(int x){return x*x;}public int g(int x,int y){return x+y;}}class B implements Computable{public int f(int x){return x*x*x;}public int g(int x,int y){return x*y;}}public c 阅读全文
posted @ 2013-04-21 21:30 wangchunmei 阅读(196) 评论(0) 推荐(0)
 
 

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)
 
 
下一页

公告


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