本帖最后由 shw16888 于 2015-4-8 14:37 编辑
- class Ball
- {
- private int num;
- private String color;
- {
- pop();
- }
- Ball()
- {
- System.out.println("num="+num+","+"color="+color);
-
- }
- Ball(int num)
- {
- this.num=num;
- System.out.println("num="+num+","+"color="+color);
- }
- Ball(int num ,String color)
- {
- this.num=num;
- this.color=color;
- System.out.println("num="+num+","+"color="+color);
- }
- public static void pop()
- {
- System.out.println("我会发出Pop响");
- }
- public void setNum(int num )
- {
- this.num=num;
- pop();
- }
- public int getNum()
- {
- return num;
- }
- class ballDemo
- {
- public static void main(String[] args) //为什么eclipse提示方法mian不能声明为“静态”,只能在静态类型或顶级类型中才能 声明静态方法
- {
- Ball b=new Ball();
- Ball b1=new Ball(3);
- Ball b2=new Ball(3,"伯丁篮球棕色");
- b.setNum(5);
- System.out.println(b1.getNum());
- }
- }
- }
复制代码
|
|