上进小青年

导航

杂谈7

1.内部类的两种声明方法(I0是I 的内部类)

(1)new I().new I0().aha();

(2)I i=new I();

I.I0 i1=new I().new I0();

2.在方法中定义类也是内部类

3. String s="啊哈";

String s1="啊哈";

String s2=new String("啊哈");

System.out.println(s==s1);“==”比较的是地址

System.out.println(s==s2);

输出

 

S1.equal(s2);比较的是内容

S和s1在栈里所指的地址是一样的,而与s2则不同

4.构造器私有后,该类在其他类中不可见

5.枚举类:有限个对象

6.枚举类与一般类的区别

(1)对象是常量

(2)构造器私有

(3)不可以继承

(4)枚举直接父亲Enum,间接还是object

7.举例

public enum ChengHu {M,F,S,B;

  public void zhongWen(){

    switch(this){

    case M:System.out.println("妈妈");

    case F:System.out..println("爸爸");

    case S:System.out.println("姐姐");

    case B:System.out.println("哥哥");

         }

  }

}

8. public class b {

public static void main(String[] args) {Planet.S.ok();(调用ok函数的方法)

      for(Planet e:ChengHu.values())//(遍历枚举类的方法)

      System.out.println(e);

  }

}

9.基本数学函数

Math.ceil(a);-----------------------比a大的最小的double值

Math.floor(a);----------------------比a小的最大的double值

Math.random ();------------------返回0.0~1.0的数

PS:要返回x~y之间的随机数

◎Math.random ()*(y-x)+x;

◎Math.random ()*(y-x+1)+x

Math.round (a);-------------------a的四舍五入的数

10. Random r=new Random();

      System.out.println(r.nextInt(n));

返回小于n的随机整数

11. String s3=s1+s2;一共要开三个堆,非常慢

String s4=s1.concat(s2);      

            

posted on 2017-01-15 19:20  上进小青年  阅读(109)  评论(0编辑  收藏  举报