scjp复习笔记(3)
发布日期:2021-06-30 11:34:30 浏览次数:3 分类:技术文章

本文共 2259 字,大约阅读时间需要 7 分钟。

Example 16

Java1.6中引入了许多新的接口,其中的两个是:java.util.NavigableSetjava.util.NavigableMap

import java.util.*;

public class Ferry {

  public static void main(String [] args) {   

    TreeSet<Integer> times = new TreeSet<Integer>();

    times.add(1205);   // add some departure times

    times.add(1505);

    times.add(1545);

    times.add(1830);

    times.add(2010);

times.add(2100);

// Java 5 version

TreeSet<Integer> subset = new TreeSet<Integer>();

subset = (TreeSet)times.headSet(1600);

System.out.println("J5 - last before 4pm is: " + subset.last());

TreeSet<Integer> sub2 = new TreeSet<Integer>();

sub2 = (TreeSet)times.tailSet(2000);

System.out.println("J5 - first after 8pm is: " + sub2.first());

// Java 6 version using the new lower() and higher() methods

System.out.println("J6 - last before 4pm is: " + 

times.lower(1600)

);

    System.out.println("J6 - first after 8pm is: " + 

times.higher(2000)

);

  }

}

This should produce the following:

J5 - last before 4pm is: 1545

J5 - first after 8pm is: 2010

J6 - last before 4pm is: 1545

J6 - first after 8pm is: 2010

Example 17

Example 18 

emun不可以在方法当中声明,这样会出现编译错误。

Example 19

(貌似在main函数里面,参数 i 的修饰符不合法;只允许使用终态)Public  protected private 不可以用来修饰变量,只允许使用终态。在类里面还是行的。

Examlpe 20 

注意下面的比较:

int x = 100; float y = 100.0F;

if (x == y){ System.out.println(“Equal”);}

Result:Equal

B. int x = 100; Integer y = new Integer(100);

if (x == y) { System.out.println(“Equal”);}

Result:Equal

C. Integer x = new Integer(100);

Integer y = new Integer(100);

if (x == y) { System.out.println(“Equal”);}

False

D. String x = new String(“100”);

String y = new String(“100”);

if (x == y) { System.out.println(“Equal”);}

False

E. String x = “100”;

String y = “100”;if (x == y) { 

System.out.println(“Equal”);}

True

Example 21

最终类不可以有它的子类

下面写法是错误的:

1. final c{}

2. public class a extends c{

3.      Public static void main(String a [])

4.      {

5.      }

6. }

编译的时候出现下面的错误:类型 a 不能成为终态类 c的子类

Example 22

静态方法是不可以继承的,如下面所示:

/**

 * @author   

 * E-mail

 * QQ

 */

class A{

    static void a1() {

System.out.println("parent class!");

}

}

 class B extends A {

 static void a1() {

System.out.println("sub class!");

}

}

public class Textclass{

/**

 * @param args

 */

public static void main(String[] args) {

// TODO 自动生成方法存根

B tc=new B();

A a=new B();

tc.a1();

a.a1();

}

}

B类中static void a1()不是继承A类中的方法,而是自己的方法!

 

转载地址:https://iteblog.blog.csdn.net/article/details/6842764 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:安装postgreSQL出现configure:error:readline library not found解决方法及pg安装全过程
下一篇:scjp复习笔记(2)

发表评论

最新留言

表示我来过!
[***.240.166.169]2024年04月10日 21时08分00秒