2018.6.19 Java Mock Exam (basic exercise)

Source: Internet
Author: User
Tags true true stringbuffer

Java Mock Exam (basic problem) one, single choice (1 points per question * 50 = 50 points) 1. A set of JDK tools is used during the execution of a Java program, where Javac.exe refers to (B)
A.java语言解释器B.java字节码编译器C.java文档生成器D.java类分解器
2. In the Java language, Java attributes that are not allowed to use pointers are (D)
A.可移植B.解释执行C.健壮性D.安全性
3. 00101010 (&) 00010111 statement execution result is (C)
A.11111111B.00111111C.00000010D.00000000
4. In Java statement: The result of the 37.2%10 operation is (A)
A.7.2B.7C.3D.0.2
5. The 0.6332 data type is (B)
A.floatB.doubleC.FloatD.Double
6. System.out.println ("5" + 2), the output should be (A)
A.52B.7C.2D.5 System.out.println("5"+2+1);//521
7. The following method, when the input is 2, the return value is how much (D)
public static int getValue(int i) {        int result = 0;        switch (i) {        case 1:            result = result + i;        case 2:    //从这里进去    result=0+2*2  =4            result = result + i * 2;        case 3:     //因为没有break结束   所以直接进入   result= 4+2*3  =10            result = result + i * 3;        }        return result;}A.0B.2C.4D.10
8. In the following statement, the multi-branch statement is (B)
A.if语句B.switch语句C.do while语句D.for语句
9. The result of the following program execution is (C).
public class Ex6 {    public static void main(String[] args) {        char ch=‘8‘;        int r=10;        switch(ch+1) {  //第一次 9     第二次  15+1            case ‘7‘: r=r+3;            case ‘8‘: r=r+5;            case ‘9‘: r=r+6;//9+6=15                break;            default: ;        }    System.out.print(r);    }}A.14B.13C.16D.10
10. What is the value of a after executing the following program code (C)
public class Ex10 {    public static void main(String[] args) {       int a=0;       int c=0;        do{        --c;        a=a-1;        }while(a>0);        System.out.println("aa"+a);    }    }A.0       B.1       C.-1      D.死循环do while的特点:    当不满足循环条件就退出,这种循环的特点是至少会执行循环一次,先执行循环后判断
11. The result of the following program code execution is: (B)
public class Ex11 {    public static void main(String[] args) {      for(int i = 0;i<5;i++){        System.out.println(i++);        if(i%3==0)        break;        }       }}A.0   1   2B.0   2C.0   2   4D.0   1   3使用break语句是跳出循环执行循环之后的语句,而continue语句是中止本次循环继续执行下一次循环。
12. The error in the following array declaration is (D)
A.int[] a         B.int a[]C.int[][] a       D.int a[10]
13. Execute code "int[] x=new int[25];" After, the following (A) describes the correct
A.x[24]为0B.x[24]未定义C.x[25]为0D.x[0]为空
14. The following statement is in the main method of the application, and the result of the output is (A)
public class Ex14 {    public static void main(String[] args) {       int[]  x= {122,33,55,678,-987};        int  y= x[0];        for(int i=1;i<x.length;i++){            if(x[i]>y)                y =x[i];            }            System.out.println(y);    }}A.678   B.122   C.-987   D.33
15. Method MethodA The return type is (a)
public class ReturnIt{     return Type methodA(byte x, double y) {       return (short) x/y * 2;   }}A.int    B.byte    C.long  D.double
16. The result of running the following program is (A)
public class X {    private static int a;    public static void main(String [] args) {        modify(a);        System.out.println(a);    }    public static void modify(int a) {        a++;    }}A.0       B.1       C.程序编译失败       D.程序抛出异常
17. Given the method structure of the following Java program, the method body implementation statement is correct (C)
public String change(int i){ //方法体 }A.return 100;B.return ‘a’;C.return i+””;D.return i;
18. The following statements are correct (a)
A.形式参数可以被视为local variable (局部变量)B.形式参数可被字段修饰符修饰C.形式参数为方法被调用时,真正被传递的参数D.形式参数不可以是对象A:形式参数和局部变量一样,生命周期随着方法的结束而终结,离不开方法。在Java中形式参数都是值传递的,所以可以视为一个局部变量。B:Java中字段修饰符有:public、protected、default、private、final、static。在形式参数中,如果要使用字段修饰符,只能使用final修饰符。其他任何修饰符都能引起编译器错误。C:java中方法没有引用调用,调用的形参都是拷贝的。 D:形式参数可以是值或者对象。
19. There is a method in a class: void Getsort (int x), and the following can be declared as overloads of this method (C)
A.public getSort(float x)   没有返回类型 一定是构造函数 不能重载B.int getSort(int y)   参数一样不是重载C.double getSort(int x,int y)D.void get(int x, int y)重载判定就是方法名相同传入的参数不同  参数列表不同
20. Given the following
public class X {    public static void main(String [] args) {       String d="bookkeeper";        d.substring(2,9);//这里需要重新接收字符串  含义是重第二个开始到第九个位置结束 okkeepe        d = "u"+d; //还是用最开始的d字符串        System.out.println(d);    }}What is the result (  B )A.uookkeewooB.ubookkeeperC.ubookkeepertooD.An exception is thrown at runtime总结:substring(x)是从字符串的的第x个字符截取     
21. The result of running the following program is (A)
public class Test1{    public static void main(String args[]){        String a="1234";        String b="1234";        String c = new String("1234");        System.out.println(a==b);//True  比较的是地址        System.out.println(a==c);//false 比较的是地址        System.out.println(a.equals(c));//true  比较的是内容    }}A.true false trueB.true true  falseC.true false falseD.true true  true
22. Given the following Java code, after compiling the run, the result of the output will be (B)
public class Test {    public static void main(String args[]) {        String s1 = new String("Test");        String s2 = new String("Test");        if (s1 == s2)            System.out.println("Same");//比较的是地址   new出来是开辟新的空间        if (s1.equals(s2))            System.out.println("Equals");//比较的是内容    }}A.SameB.EqualsC.SameEqualsD.什么都不输出
23. The following code executes the result (a)
public class TT{    public static void main(String[]args){        String a = "A";        StringBuffer b = new StringBuffer("B");        StringBuffer c = new StringBuffer("C");//初始化出的StringBuffer对象的内容就是字符串”C”        change(a,b,c);            System.out.println(a+","+b+","+c);//A,B1,C}static void change(String s,StringBuffer s1,StringBuffer s2){    s=s+"1";    s1.append("1");        System.out.println("1"+s2);// C    s2=new StringBuffer("C1");C  //初始化出的StringBuffer对象的内容就是字符串”C1”        System.out.println("2"+s2);// C1    }}A.A,B1,CB.A1,B1,C1C.A,B,CD. A1,B,C注意:String类是final变量不可以修改,stringbuffer 是new出来的,生成的对象根据括号里面的内容来生成
24. The following statements are correct (C)
A.class中的constructor不可省略B.constructor必须与class同名,但方法不能与class同名C.constructor在一个对象被new时执行D.一个class只能定义一个constructor方法可以和类名同名的,和构造方法唯一的区别就是,构造方法没有返回值。
25. With regard to the deletion of objects, the following statements are correct (B)
A.必须由程序员完成对象的清除B.Java把没有引用的对象作为垃圾收集起来并释放C.只有当程序中调用System.gc()方法时才能进行垃圾收集D.Java中的对象都很小,一般不进行删除操作解释:在Java中定义对象时往往通过new运算符为其分配内存空间,于是当不再希望使用这个对象时需要释放掉它所占用的内存。在Java中,释放内存的工作是由系统自动隐含的进行,编程人员无须关心。
26. In the following description, the error is (A)
A.Java要求编程者管理内存B.Java的安全性体现在多个层次上C.Applet要求在支持Java的浏览器上运行D.Java有多线程机制在编译层、解释层、平台层分别作不同的安全检查Applet本身不能运行,但能够嵌入到Web浏览器中运行多线程是Java程序的并发机制,它能同步共享数、处理不同的事件
27. In the class test shown below, there is a common (C) construction method
public class Test{private int x;public Test(){  //1    x = 35;}public void Test(double f) {    this.x = (int)f;}public Test(double f){  //2    this.x = (int)f;}public Test(String s) { }  //3}A.1B.2C.3D.4构造方法是与clss同名但是无返回值参数可以不同
28. Set A to the defined class name, and the following declares that the object A of Class A is correct in the statement (a)
A.public  A  a=new  A( );B.public  A  a=A( );C.A  a=new  class( );D.a  A
29. An incorrect description of the static member of the class is ()
A.静态成员不属于对象,是类的共享成员B.静态数据成员初始化的时机要优先于实例成员C.静态成员函数不拥有this指针,需要通过类参数访问对象成员D.只有静态成员函数可以操作静态数据成员
30. The following statements are correct (C)
A.Java中包的主要作用是实现跨平台功能B.package语句只能放在import语句后面C.包(package)由一组类(class)和界面(interface)组成D.可以用#include关键词来标明来自其他包中的类
31. The right thing to say about inheritance is (B)
A.子类将继承父类所有的属性和方法B.子类将继承父类的非私有属性和方法C.子类只继承父类public方法和属性D.子类只继承父类的方法,而不继承属性
32. The following modifiers are not related to access control (D)
A.privateB.publicC.protectedD.final
33. For member variables that are privately decorated by the private access control, the following statement is correct ()
A.可以被三种类所引用:该类自身、与它在同一个包中的其他类、在其他包中的该类的子类B.可以被两种类访问和引用:该类本身、该类的所有子类C.只能被该类自身所访问和修改D.只能被同一个包中的类访问
34. About which object members occupy memory which is correct (B)
A.同一个类的对象共用同一段内存B.同一个类的对象使用不同的内存段,但静态成员共享相同的内存空间C.对象的方法不占用内存D.以上都不对
35. Which of the following classes is declared correct (D)
A.abstract final class HI{}B.abstract private move(){}C.protected private number;D.public abstract class Car{}类声明的格式为: [修饰符]class类名[extends父类名][implements类实现的接口列表]{...} 修饰符指明类的访问控制符和类型说明符。修饰符包括:public、默认(也称friendly)、 abstract、final。public和默认(也称friendly)为访问控制符,abstract和final是类型说明符。访问控制符可以和类型说明符搭配使用.
36. The output of the following program is (D)
class Base {    public Base(String s) {        System.out.println("B");    }}class Derived extends Base {    public Derived(String s) {        System.out.println("D");    }}public class Test{    public static void main(String[] args) {        new Derived("C");    }}A.BDB.DBC.CD.编译错误
37. When using the super and the This keyword, the following description is correct (A)
A.在子类构造方法中使用super()显示调用父类的构造方法,super()必须写在子类构造方法的第一行,否则编译不通过B.super()和this()不一定要放在构造方法内第一行C.this()和super()可以同时出现在一个构造函数中D.this()和super()可以在static环境中使用,包括static方法和static语句块解释:    super()和this()类似,区别是,super从子类中调用父类的构造方法,this()在同一类内调用其它方法。    3)super()和this()均需放在构造方法内第一行。    4)尽管可以用this调用一个构造器,但却不能调用两个。    5)this和super不能同时出现在一个构造函数里面,因为this必然会调用其它的构造函数,其它的构造函数必然也会有super语句的存在,所以在同一个构造函数里面有相同的语句,就失去了语句的意义,编译器也不会通过。    6)this()和super()都指的是对象,所以,均不可以在static环境中使用。包括:static变量,static方法,static语句块。    7)从本质上讲,this是一个指向本对象的指针, 然而super是一个Java关键字。
38. What happens when you compile and run the following program columns (A)
class A{public int getNumber(int a){return a+1;   }}class B extends A{   public int getNumber(int a, char c){      return a+2;}public static void main(String[] args){    B b=new B();    System.out.println(b.getNumber(0));   }}A.编译错误B.运行错误C.1D.2
39. Read the following procedure to choose which one is the correct output () No picture
A.static A I’m A class static B I’m B classB.I’m A class I’m B class static A static BC.static A static B I’m A class I’m B classD.I’m A class static A I’m B class static B注释:静态成员是累的共享成员     静态变量要在定义时就初始化     调用静态方法时通过类或对象激活
40. The following question: The variable that cannot be manipulated in the subclass Child2 Method F () is (a)
package a;class Parent{private int i=20;protected int j=30;public int k=40;int h=50;}class Child1 extends Parent {    }class Child2 extends Child1{void f(){   }}A.i            B.j          C.k          D.h
41. The following programs run as a result ().
class Parent{    int i=20;    int j=30;    void f(){    System.out.print(” “+i);   }}class Child extends Parent {    int i=30;    int k=40;    void f(){    System.out.print(” “+i);}    void g(){        System.out.print(” “+k);}public static void main(String args[]){Parent x=new Child();System.out.print(x.i);    x.f();Child x1=(Child)x;System.out.print(” “+x1.i);x1.f();   }}A.30 30 30 30       B.20 20 20 20     C.20 30 30 30     D.都不对
42. In Java (C).
A.一个子类可以有多个父类,一个父类也可以有多个子类B.一个子类可以有多个父类,但一个父类只可以有一个子类C.一个子类只可以有一个父类,但一个父类可以有多个子类D.上述说法都不对
43. Which of the following statements is correct (D)
A. abstract修饰符可修饰字段、方法和类B. 抽象方法的body部分必须用一对大括号{ }包住C. 声明抽象方法,大括号可有可无D. 声明抽象方法不可写出大括号
44. Set int a=-2, the value of the expression a>>3 is (D).
A.8B.0C.3D.-11000 0010    右移之后 1000  0001
45. To see the following procedure, please give the result: (B)
public class TestObj{    public static void main(String[] args){        Object o=new Object(){            public boolean equals(Object obj){                return true;    }};    System.out.println(o.equals("Fred"));    }}A.运行时抛出异常B.trueC.FredD.第三行编译错误
46. The following procedural questions (C)
interface C {   name = “”;   void f();   abstract void g();   void h(){};}A.第2行编译错误B.第4行编译错误C.第5行编译错误D.没有错误,正确
47. The following description of the abstract class is correct (D)
A.抽象类没有构造方法B.抽象类必须提供抽象方法C.抽象类可以通过new关键字直接实例化D.有抽象方法的类一定是抽象类
48. The following description is incorrect (C)
A.abstract 可以修饰类、接口、方法B.abstract修饰的类主要用于被继承C.abstract 可以修饰变量D.abstract修饰的类,其子类也可以是abstract修饰的E.final可以用来修饰类、方法、变量
49. With regard to String,stringbuilder and StringBuffer, the error is described as (B)
A.对String对象的任何改变都不影响到原对象,相关的任何change操作都会生成新的对象B.StringBuilder是线程安全C.StringBuffer是线程安全D.可以修改StringBuilder和StringBuffer的内容String final 修饰,不可变StringBuilder  非线程安全、不使用多线程的情况下,效率高StringBuffer 线程安全
50. There can be two functions of the same name in the definition of a class, a phenomenon called a function (C).
A.封装B.重写C.重载D.继承
Second, multi-choice (2 points per question * 10 = 20 points) 1. The final statement is correct (C D)
A.final一般修饰静态变量,静态变量不会发生变化B.final不能修饰抽象类,抽象类是用来继承的C.final修饰的方法,不能被重写,但是可以重载D.final修饰类,类不能被继承, String就是final类
2. The following identifiers are not valid (ACD)
A.new    B.$Usdollars    C.1234    D.car.taxi
3. The following error initialization statement is (CD)
A.char str[]=”hello”;B.char str[100]=”hello”;C.char str[]={‘h’,’e’,’l’,’l’,’o’};D.char str[]={‘hello’};
4. In Java, the following statement about the package is correct (a D)
A.包的声明必须是源文件的第一句代码。B.包的声明必须紧跟在import语句的后面。C.只有公共类才能放在包中。D.可以将多个源文件中的类放在同一个包中。
5. The description of the array is correct (ACD)
A. 数组有一个属性是lengthB. 数组有一个方法是length()C. 数组是固定长度,相同类型,连续的物理存储空间D. 数组的声明可以是基本数据类型,也可以是对象类型数组,但是数组本身是引用类型
6. For the binary search method, the following description is correct (a C)
A.可用于数组B.可用于单链表C.只能在已排序的数据上进行D.最坏情况下时间复杂度是O(N*LogN)  二分查找需要在已排序的数组上进行,需要能够通过下标直接索引到值,因此无法在链表上进行二分查找首先要求数据是有序的,同时要求能随机访问数据元素, 有序数组可以, 链表不行,二分查找因为每次都是从中间点开始查找,所以最坏情况是目标元素存在于最边缘的情况。最坏为O(LogN)
7. The following is a description of the inheritance of the class, right? B
A.一个类可以直接继承多个父类B.一个类可以具有多个子类C.子类会自动拥有父类定义的有效访问权限的方法以及成员变量D.一个类继承另一个类必须重写父类的方法
8. What are the following description errors? (B D)
A.类只能继承一个父类,但是可以实现多个接口B.抽象类自身可以定义成员而接口不可以C.抽象类和接口都不能被实例化D.一个类可以有多个基类和多个基接口Java不支持多继承,只能有一个基类接口中定义的成员变量默认为public static final,只能够有静态的不能被修改的数据成员;而且,必须给你赋初值,其所有成员方法都是public、abstract的,而且只能被这两个关键字修饰。
9. What is the storage structure of the data? (A B)
A.顺序存储B.链式存储C.图存储D.二叉存储

10. The following code is said to be correct ()

Final class d{

final int no=1;

final void F () {

Final String s= "";

s = "some thing";

}

}

A The class cannot be inherited

B Line 2nd does not assign a value to No

C The F method cannot be overridden

D No compilation errors

Three, The blank question (2 points per question * 5 = 10 points)

1. If 4 classes are defined in a Java source program file, compiling the source program file with the compile command will generate a bytecode file with the extension class.

2, set x = 2 The value of the expression (x + +) is.

3. There are two kinds of transformations between various data types in the Java language:,.

4, Java design has a keyword, which not only prevents the memory address calculation error problem, but also saves the programming memory to allocate the trouble.

5, we put the keyword in the Java program before the method name, to implement the subclass calls the parent class method.

Four, simple answer (5 points per question * 4 = 20 points)

1. What are the similarities and differences between abstract class and interface (interface)?

2. What is a Java virtual machine? Why is Java called a "platform-agnostic programming language"?

3, explain the difference between overload and override.

4, the difference between & and &&?

Five, programming problems (10 points per question * 2 = 20 points) 1, the number of the 100 within the prime (can be divided by 1 and itself).
2. Use the Java programming program to bubble sort the array.
public class X{    public static void main(String[] args){        int[] arr = {34,2,6,4,23};        for(int i =0;i<arr.length;i++){            for(int j = 0;j<i;j++){                if(arr[i]>arr[j]){                    int temp = arr[i];                    arr[i] = arr[j];                    arr[j] = temp;                }            }        }        for(int i = 0;i<arr.length;i++){            System.out.println(arr[i]);        }    }}

2018.6.19 Java Mock Exam (basic exercise)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.