目录
盛世吉软java基础试题笔试部分
15.给出以下代码,请问在程序的第6行插入那条语句,改程序可依次打印输出11、10、9?(C)
2.根据下面的代码,String s = null;会抛出NullPointerException异常的有(AC)。
1.谈谈final, finally, finalize的区别。
4.try {}里有一个return语句,那么紧跟在这个try后的finally {}里的code会不会被执行。
5.Math.round(11.5)等於多少? Math.round(-11.5)等於多少?
2、从控制台中读入一个文件名, 判断该文件是否存在你的某个盘下。 如果该文件存在, 则在原文件相同路径下创建一个文件名为“copy_原文件名”的新文 件, 该文件内容为原文件的拷贝。
4、随机生成10个百位以内数字并存入集合中(任意集合均可,自行决定)。 利用自己擅长的方式对其10个数字进行排序,排序后按小到大方式输出。
姓名 得分
System.out.println(a==b);输出结果为:true
| public class Test1{ public static void main(String args[]){ float t=9.0f; int q=5; System.out.println((t++)*(--q)); } } |
| String s = "Hello" + 9 + 1; String s1 = 9 + 1 + "Hello"; System.out.println(s +"+"+ s1); |
| int a=0; int c=0; do{ --c; a=a-1; }while(a>0); |
| 1.class HasStatic{ 2. private static int x=100; 3. public static void main(String args[ ]){ 4. HasStatic hs1=new HasStatic( ); 5. hs1.x++; 6. HasStatic hs2=new HasStatic( ); 7. hs2.x++; 8. hs1=new HasStatic( ); 9. hs1.x++; 10. HasStatic.x- -; 11. System.out.println(“x=”+x); 12. } 13. } |
| public class Example { public static void main(String[] args) { System.out.println("string".endsWith("")); } } |
| 1.public class Example { 2. public static void main(String[] args) { 3. double x[] = { 10.2, 9.1, 8.7 }; 4. int i[] = new int[3]; 5. for (int a = 0; a < x.length; a++) { 6. 7. System.out.println(i[a]); 8. } 9. } 10.} |
1、一般Java程序的类体由两部分组成:一部分是 属性 ,另一部分是 方法
2、子类对父类继承来的属性重新定义称为 重写 。子类对自身拥有的同名方法的重新定义称 重载 。
3、.⾯向对象的计算机语⾔⼀般应有3 个基本特征,分别是 封装 、 继承 和 多 态 。
4、若有byte b=1;int i=0; while(++b>0) i=i+1;,则while 退出时i 的值为 126 。
5、不能覆盖⽗类中的 final ⽅法和 private ⽅法。
final—修饰符(关键字)如果一个类被声明为final,意味着它不能再派生出新的子类,不能作为父类被继承。因此一个类不能既被声明为 abstract的,又被声明为final的。将变量或方法声明为final,可以保证它们在使用中不被改变。被声明为final的变量必须在声明时给定初值,而在以后的引用中只能读取,不可修改。被声明为final的方法也同样只能使用,不能重载。
finally—异常处理时提供 finally 块来执行任何清除操作。如果抛出一个异常,那么相匹配的 catch 子句就会执行,然后控制就会进入 finally 块(如果有的话)。
finalize—方法名。Java 技术允许使用 finalize() 方法在垃圾收集器将对象从内存中清除出去之前做必要的清理工作。这个方法是由垃圾收集器在确定这个对象没有被引用时对这个对象调用的。它是在 Object类中定义的,因此所有的类都继承了它。子类覆盖 finalize() 方法以整理系统资源或者执行其他清理工作。finalize() 方法是在垃圾收集器删除对象之前对这个对象调用的。
wait():使一个线程处于等待状态,并且释放所持有的对象的lock。
sleep():使一个正在运行的线程处于睡眠状态,是静态方法,调用此方法要捕捉InterruptedException异常。
notify():唤醒一个处于等待状态的线程,注意的是在调用此方法的时候,并不能确切地唤醒某一个等待状态的线程,而是由JVM确定唤醒哪个线程,而且不是按优先级。
Allnotity():唤醒所有处入等待状态的线程,注意并不是给所有唤醒线程一个对象的锁,而是让它们竞争。
Error表示系统级的错误和程序不必处理的异常,
Exception表示需要捕捉或者需要程序进行处理的异常。
会,而且必修被执行
Math.round(11.5)==12
Math.round(-11.5)==-11
克隆前c1: a=100 b[0]=1000
克隆后c1: a=100 b[0]=1000
克隆后c2: a=50 b[0]=5
- class Truck extends Car {
-
- private Integer payload;
-
- public Integer getPayload() {
- return payload;
- }
-
- public void setPayload(Integer payload) {
- this.payload = payload;
- }
-
- public String show() {
- return super.show() + ",载重量:" + payload;
- }
-
- }
-
- class Car extends Vehicle {
-
- private Integer loader;
-
- public Integer getLoader() {
- return loader;
- }
-
- public void setLoader(Integer loader) {
- this.loader = loader;
- }
-
- public String show() {
-
- return super.show() + ",人数:" + loader;
-
- }
-
- }
-
- class Vehicle {
- private Integer wheels;
- private Integer weight;
-
- public Integer getWheels() {
- return wheels;
- }
-
- public void setWheels(Integer wheels) {
- this.wheels = wheels;
- }
-
- public Integer getWeight() {
- return weight;
- }
-
- public void setWeight(Integer weight) {
- this.weight = weight;
- }
-
- public String show() {
- return "汽车的车轮个数为:" +wheels + ",车重:" + weight;
- }
- }
-
-
- public class Ch01 {
-
- public static void main(String[] args) {
- Vehicle vehicle = new Vehicle();
- vehicle.setWeight(200);
- vehicle.setWheels(4);
- System.out.println(vehicle.show());
-
- Car car = new Car();
- car.setWheels(4);
- car.setWeight(150);
- car.setLoader(5);
- System.out.println(car.show());
-
- Truck truck = new Truck();
- truck.setWheels(12);
- truck.setWeight(500);
- truck.setPayload(1000);
- truck.setLoader(2);
-
- System.out.println(truck.show());
-
- }
-
- }
- public class Ch02 {
-
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.println("请输入文件名:");
- String fileName = sc.next();
- System.out.println("请输入盘符:(例如:E:/)");
- String disk = sc.next();
-
- File target = new File(disk,fileName);
-
- if(target.exists()) {
- File current = new File(disk,"copy_" + fileName);
- InputStream in = null;
- OutputStream out = null;
- try {
- current.createNewFile();
- in = new FileInputStream(target);
- out = new FileOutputStream(current);
- byte [] buf = new byte[1024];
- int len;
- while((len = in.read(buf)) != -1){
- out.write(buf,0,len);
- }
- } catch (IOException e) {
- throw new RuntimeException(e);
- } finally {
- if(out != null) {
- try {
- out.close();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- if(in != null) {
- try {
- in.close();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- }
- }else {
- try {
- target.createNewFile();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- }
-
- }
- public class Ch03 {
-
- public static void main(String[] args) {
- String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
- List
list = new ArrayList<>(100); - StringBuilder strb = new StringBuilder();
- int length = str.length();
- for (int i = 0; i < 100; i++) {
- strb.delete(0,strb.length());
- for (int j = 0; j < 10; j++) {
-
- // 生成0-length的随机数
- // [0,length),包含0,不包含length
- // 通过String的charAt方法取出指定的字符,然后进行拼接
- // 0是最小值,length是最大值
- // 0-length
- strb.append(str.charAt((int)(Math.random() * length)));
- }
- list.add(strb.toString());
- }
- System.out.println("数据生成成功!");
- Scanner sc = new Scanner(System.in);
- System.out.println("请输入一个十位的字符串:");
- String target = sc.next();
- if(list.contains(target)){
- System.out.println("字符串在对应的容器中存在!");
- }else {
- System.out.println("字符串在对应的容器中不存在!");
- System.out.println("容器中的字符串为:" + list);
- }
- }
- }
- public class Ch04 {
-
- public static void main(String[] args) {
-
- List
list = new ArrayList<>(10); - Random random = new Random();
- for (int i = 0; i < 10; i++) {
- int i1 = random.nextInt(100);
- list.add(i1);
- }
- System.out.println("数据生成成功:" + list);
- Collections.sort(list);
- System.out.println("排序过后的数据为:" + list);
- }
- }