南财JAVA期末终极版.doc_第1页
南财JAVA期末终极版.doc_第2页
南财JAVA期末终极版.doc_第3页
南财JAVA期末终极版.doc_第4页
南财JAVA期末终极版.doc_第5页
已阅读5页,还剩11页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

一、单项选择题(共15小题,每题1分,共计15分)二、填空题(共5空,每空1分,共计5分)三、名词解释(共4小题,每题5分,共计20分)四、阅读程序题(共5小题,每题4分,共计20分)五、程序设计题(共3小题,每题10分,共计30分)六、改错题(共 1 小题,计 10 分)一、单项选择题1、构造某个类的实例,使用关键字new实现。例如,类A继承自类B,要创建A的实例,可以使用: A a = new A( ); B a = new A( );其中第二种方式即通过基类型的引用指向子类型的实例。对于接口也是一样的。即如果类C实现了接口I,要创建C的实例,可以使用:C b = new C( );I b = new C( );2、分支结构:if-else、switch结构:可以只有if语句而没有else语句;else语句必须和最近的没有配对的if语句配对。switch结构中可以没有default语句;每个case中可以有break,也可以没有。3、循环语句一共有三种:for、while、do-while。其中do-while是先执行循环体,然后再判断循环条件。三种循环的循环体都可以为空。4、访问控制符主要有:private、protected、public。5、数组中元素的下标从0开始,最大为数组元素个数-1。6、判断某给定循环中循环执行的次数,比如:for(int i=0;i=5;i=i+1)System.out.println(第+i+次循环); 判断上述循环执行的次数。7、Java语言不支持多重继承,但是通过接口可以实现多重继承的效果;Java程序有两类:Application和Applet;Java中类的方法可以使用public或者private或者protected进行修饰,也可以不适用任何修饰符。8、同一个类的实例(对象)之所以能相互区分,是因为他们占用不同的内存单元,但是静态成员共享相同的内存空间。9、+、-运算符10、要创建对象,必须先定义类;对象的构成包括属性和方法,但是不是必须的,可以没有属性,也可以没有方法。属性可以是简单变量,也可以是一个复杂变量(即对象)11、标识符的命名规则12、Java中,要编译一个类使用javac.exe(编译器)命令,要解释执行一个类使用java.exe命令(虚拟机)。13、Java语言借鉴了C语言、C+语言的很多语法特征,其最主要的特点就是跨平台。14、Java语言是区分大小写的;所有变量必须先定义才能使用;Java是强类型语言,即变量类型必须要明确定义;Java中一条语句的结束必须要使用分号;源文件的扩展名为.java,经过编译以后得到字节码文件,扩展名为.class。一个源文件中可以定义多个类,但是其中只能有一个class是public class,而且public class的名字必须和源文件的名字相同。一个源文件编译以后,可能会得到多个字节码文件,即源文件中的每个类都会产生一个对应的字节码文件。15、double和Double是不同的类型。double是简单类型,仅仅存储了一个值;而Double是对象类型,是double的封装类,除了存储值以外,还提供一些方法,比如Double.parseDouble(12.34)可以从字符串12.34中得到数值12.34。16、P35类型的自动转换。17、构造函数的调用时机:在使用 new创建对象时自动调用。18、执行for( int i=0, j=3; j 6; j+=2 ) i=i+j;后,i的值是?19、复合赋值运算符:+=、-=、*=、/=表示什么意义?20、循环语句for ( int i = 0; true ; i+) ;是否正确呢? 是正确的。循环语句的循环体可以为空语句;循环条件为true,则表示为永久循环。21、在继承中,子类将继承父类的所有属性和方法。22、一个类中可以有多个构造函数,这多个构造函数具有相同的名字(即类名),可以具有不同的参数,通过参数的不同进行区分(即构造函数的重载)。23、八进制整数、十六进制整数的表示方法。24、数组的定义:数组是具有相同类型数据元素的集合。25、字符类型变量的编码是Unicode编码,英文字母的编码是连续的,数字的编码也是连续的。字符A和字符a的编码分别是多少?二、填空题1、Java中的八种简单数据类型是哪些?各自的长度是多少字节?2、类的定义方法、对象如何创建3、数组如何创建?数组中元素的个数使用什么属性表示?length4、1/2跟1.0/2的区别是什么?5、main方法的原型一般为:public static void main(String args)其中参数args为String,即String类型的数组,在这个数组中保存的就是用户通过命令行传入的参数,比如我们使用java执行一个类HelloWorld时,语法如下:java HelloWorld t1 t2 123在上面的命令中,java指的是java.exe,是用于执行一个java程序的java解释器程序,HelloWorld是要被执行的java类,t1、t2、123是传入的三个参数,将被保存在Sting类型的数组args中,即args0为t1,args1为t2,args2为123。如果需要将某个字符串转换为数值,则需要使用下面的语句:int i = Integer.parseInt(123);6、Java中的流程控制结构主要有:顺序结构、分支结构、循环结构7、Java语言中的内存管理,不需要程序员编程实现。Java本身提供了垃圾收集机制,可以简化内存的管理。8、字符串是使用双引号引导的一串字符,可以是0个字符、1个字符或者多个字符;字符串的长度可以使用字符串对象的length方法(不是length属性)得到:“abc”长度为3“abcn”的长度呢?(不是5!)9、要定义一个类所属于的包,使用package语句进行定义;要包含/引用某个包中的类,则需要使用import语句。比如,要使用java.io包中的所有类,则应该在程序开始处加上:import java.io.*;要创建一个包myPackage,则应使用:package myPackage;10、接口的定义使用interface;抽象类的定义使用abstract关键字;实现一个接口使用implements;继承一个基类使用extends。11、两个整数相除,结果是怎样的?比如3/8值为?12、设有数组定义:int MyIntArray = 10 , 20 , 30 , 40 , 50 , 60 , 70;则执行以下几个语句后的输出结果是?。int s = 0 ;for (int i = 0 ; i MyIntArray.length ; i + + ) if ( i % 2 = = 1 )s += MyIntArrayi ;System.out.println(s);13、取模运算符是什么?表示的意义是什么?14、数组x定义如下:int x =new int52;则x0.length 的值为是?15、Java开发环境的建立,一般需要设置path和classpath两个环境变量。16、double型变量与byte型变量进行减法运算,运算的结果类型是什么类型?涉及到的知识点:自动类型转换。17、Java中的字符使用的是16进制的Unicode编码。18、Java中采用单重继承,而不是多重继承。其中java.lang.Object是所有类的基类。19、假设x=13,y=4,则表达式x%y != 0的值是多少?值的类型是什么?三、名词解释1.short-circuit operator:P90If one of the operands of an & operator is false, the expression is false; if one of the operands of an | operator is true, the expression is true. Java uses these properties to improve the performance of these operators. When evaluating p1&p2, Java first evaluates p1 and then, if p1 is true, evaluates p2; if p1 is false, it does not evaluate p2. When evaluating p1|p2, Java first evaluates p1 and then, if p1 is false, evaluates p2; if p1 is true, it does not evaluate p2. Therefore, & is referred to as the conditional or short-circuit AND operator, and | is referred to as the conditional or short-circuit OR operator.2.method overloading:P169Two methods have the same name but different parameter lists within one class. The Java compiler determines which method is used based on the method signature.3.static variable:P278Static variables, also known as class variables, store values for the variables in a common memory location. Because of this common location, if one object changes the value of a static variable, all objects of the same class are affected.4.constructors:P270Constructors are a special kind of method. They have three peculiarities:1) A constructor must have the same name as the class itself.2) Constructors do not have a return type not even void.3) Constructors are invoked using the new operator when an object is created. Constructors play the role of initializing objects.Like regular methods, constructors can be overloaded, making it easy to construct objects with different initial data values.5.pass-by-value:P163When you invoke a method with a parameter, the value of the argument is passed to the parameter. This is referred to as pass-by-value. If the argument is a variable rather than a literal value, the value of the variable is passed to the parameter. The variable is not affected, regardless of the changes made to the parameter inside the method.6.object:P264An object represents an entity in the real world that can be distinctly identified. An object has a unique identity, state, and behavior.1) The state of an object (also known as its properties or attributes) is represented by data fields with their current values. 2) The behavior of an object (also known as its actions) is defined by methods. To invoke a method on an object is to ask the object to perform an action.Objects of the same type are defined using a common class. A class is a template, blueprint, or contract that defines what an objects data fields and methods will be. An object is an instance of a class.7.array:P198An array is a data structure which stores a fixed-size sequential collection of elements of the same type.8.data field encapsulation:P283To prevent direct modifications of data fields, you should declare the data fields private, using the private modifier. This is known as data field encapsulation.A private data field cannot be accessed by an object from outside the class that defines the private field. But often a client needs to retrieve and modify a data field. To make a private data field accessible, provide a get method to return its value. To enable a private data field to be updated, provide a set method to set a new value.四、阅读程序题1、class A String s1,s2; A(String s11,String s22)/此为构造函数 s1=s11;s2=s22; public String toString() return s1+s2+“你好”; class T public static void main(String args) /将调用类A的构造函数,并将s1初始化为“m”,将s2初始化为“n”A a = new A(“m”, “n”);a.toString();/调用对象a的toString方法,将输出“mn你好” 2、数组中元素累加的实现,%运算符的作用public class tpublic static void main(String args )int i, s = 0 ;int a = 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ;for ( i = 0 ; i a.length ; i + )if ( ai%2 != 0 ) s += ai ; System.out.println(s=+s);3、public class Person int age;String name;/构造函数,将age和name设置为指定的值public Person(int a, String n) age=a; name=n;public void hi() System.out.println(“hi,my name is:” + name + “, my age is” + age); public static void main(String args) new Person(20,“张三”).hi(); 4、数组的遍历:将数组中元素逐个输出的方法。5、System.out.print()与System.out.println()的区别:System.out.print():输出参数指定的内容后不会换行,还是在原来的那一行System.out.println():输出参数指定的内容后将换一行,下一次输出将从下一行开始嵌套循环的理解,例如:public class test5 public static void main(String args) int i,j; for(i=0;i8;i+) for(j=0;jy; System.out.println(xy=+flag); flag=zw; System.out.println(zw=+flag); 7、public class test2 public static void main(String args) trymethod();catch (Exception e)System.out.println(A);finallySystem.out.println(B); static void method()trywrench();System.out.println(C);catch (ArithmeticException e)System.out.println(D);finallySystem.out.println(E);System.out.println(F);static void wrench()throw new NullPointerException();8、public class tpublic static void main(String args)int a = 10, 20, 30, 40, 50, 60, 70;calculate(a, a6);System.out.println(the value of a0 is + a0);System.out.println(the value of a6 is + a6);static int calculate(int x, int y)for (int i = 1; i x.length; i+)if (y x.length)xi = xi - 1 + 2;return x0;9、public class Book static String name; int price; public void setPrice(int p) price=p; public void out() System.out.println(“书名是:” + name + “,价格是:” + price); public static void main(String args) B=“Java语言程序设计”;Book b=new Book();b.setPrice(20);b.out(); 10、字符a 的ASCII编码是97、字母 A 的ASCII编码是65public class tpublic static void main(String arge)int i=0;for ( char ch = 97; ch115; ch+,i+)if( i % 4 = 0 )System.out.println( );System.out.print(t +ch);11、Switch结构的执行流程12、嵌套循环的提前退出:break、continue的应用及其区别。13.public class AnimalString type=Dog: t;String name=Tom;public static void main(String args) Animal t = new Animal();System.out.print(t.type); System.out.println(); 14.考察知识点:循环、参数的传递public class LoopTestpublic static void main(String args)int m=5;System.out.println(m is : +m);calculate(m);System.out.println(At last, m is : +m);static void calculate (int n)for (int i = 0;i10;i+)n+;System.out.println(n in calculate() is: +n);五、程序设计题1、类的定义。要求实现指定的类,并体现封装的思想,要求掌握成员变量、成员方法、构造函数的定义方式、封装的实现方法等。比如,要求实现一个Rect类,表示矩形,其中有int类型的成员变量width、height,一个无参构造函数(用于将width和height都初始化为1)、一个具有两个参数的构造函数(用于将width和height初始化为由参数指定的值)、一个setRect函数(该函数具有两个参数,用于将width和height设定为由参数指定的值)、一个返回值为double类型的getArea函数(该函数用于计算矩形的面积并返回)。public class Rect private int width,height; public Rect() width=1;height=1; public Rect(int newWidth, int newHeight) width=newWidth;height=newHeight; public void setRect(int newWidth, int newHeight) width=newWidth;height=newHeight; public double getArea() return width*height; 2、输出指定形式的图形。(提示:通过循环的嵌套实现) * * * * *3、输出九九乘法口诀表。(提示:通过循环的嵌套实现)4、输出指定形式的图形。(提示:通过循环的嵌套实现) 1 2 1 2 3 2 1 2 3 4 3 2 1 2 3 4public static void printPyramid(int lines) /参数lines代表所要输出的总行数5、输出100以内所有的素数。(提示:参考教材P138-139)6、矩阵的相加:public static double addMatrix(double a, double b) /提示:通过循环的嵌套实现7、输出指定数组中的最小值:比如某数组中共有5个元素,值分别为1、-1、3、-3、5。将数组元素中的最小值输出。(提示:通过循环实现)8、数组的合并:数组A有20个元素,数组B有10个元素,实现A和B的合并,A在前,B在后。(合并:concatenate)提示:首先定义数组A和B,然后创建一个新的数组C,C的大小为A的大小与B的大小之和(A.length + B.length),然后通过循环,将A的元素逐个赋值给C的元素,之后再将B的元素逐个赋值给C中A后面的元素。9、数组中元素的互换:数组A中有n个元素,实现将A中元素前后互换,即将第1个元素和第n个元素互换;第2个元素和第n-1个元素互换提示:for(int i=0;in/2;i+) temp=Ai; Ai=An-1-i; An-1-i=temp;六、改错题主要是一些简单的语法方面的错误,比如判断相等的运算符?类的基本结构是怎样的?关键词的大小写有没有错误?部分题目答疑(掌握上面的知识点,考试时灵活应对即可):填空题2:类的定义方法、对象如何创建参考下面的示例:public class Test /这就是类定义的基本格式int a;double b;public void t() System.out.println(“Hello World.”);Test t1=new Test(); /这就是创建对象的方法填空题3、数组如何创建?数组中元素的个数使用什么属性表示?length参见下例:int array=new int5;int sum=0;array0=1; array1=2; array2=7; array3=5; array4=23;for(int i=0; iarray.length; i+)sum=sum+arrayi;System.out.println(“数组array的元素的和为”+sum);数组的创建,使用new运算符数组的大小,也就是数组中元素的个数,使用数组的length属性表示,如上例的array.length数组中的每个元素,使用数组名跟一个下标来表示,注意,下标从0开水程序阅读题7:输出结果为:EAB此题主要考察Java中的异常处理机制main是程序执行的入口,main中调用method方法,method方法调用wrench方法。在wrench中,抛出异常NullPointerException,程序流程回到method中的try块,然后转向finally(因为在method中的catch块没有针对NullPointerException进行处理),所以输出E接着,method调用结束,程序流程回到main中的try块,由于catch语句针对Exception进行了处理,所以NullPointerException被捕获,执行其中的语句,输出A最后执行finally语句,输出B程序阅读题8:此题主要考察参数传递中,涉及到数组和简单类型变量时的区别主调函数中的调用形式为calculate(a, a6);被调函数static int calculate(int x, int y)中,第一个参数为数组类型,跟主调函数中的数组a是同一个数组(因为此参数是指向数组的地址),即a就是x;第二个参数y为int类型,是简单类型,跟主调函数中的参数的值相同,即y的值为a6的值自己分析代码,考试不是原题!程序阅读题9:public class Book static String name; int price; public void setPrice(int p) price=p; public void out() System.out.println(“书名是:” + name + “,价格是:” + price); public static void main(String args) B=“Java语言程序设计”;Book b=new Book();b.setPrice(20);b.out(); 分析:程序从main函数开始执行,main是程序执行的入口点。在main中,设置Book类的静态成员变量name为“Java语言程序设计”,然后创建一个Book的实例b。通过调用b的setPrice方法,可以将b的实例变量price设置为20;然后调用b的out方法进行输出,结果为:书名是:Java语言程序设计,价格是:20学会分析代码,考试不是原题!程序阅读题11、Switch结构的执行流程可能在程序阅读题里会含有switch结构,掌握switch的执行流程,就能分析出来执行结果了程序设计题:1、类的定义,必考!在题目中会指定要创建的类名,需要包含的构造函数、成员变量、方法名等按照要求实现即可。可以参考我给出的例子2、3、4,较为类似,以4为例,分析如下:最终图形行号前导空格空格后输出有何规律? 1 13 2 1 2 22 3 2 1 2 3 31 4 3 2 1 2 3 4 40 第i行 ? ?public static void printPyramid(int lines)/参数li

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论