JAVA认证 百分网手机站

java考试习题及答案

时间:2018-03-05 19:08:47 JAVA认证 我要投稿

java考试习题及答案

  选择题

  3、在Java Applet程序用户自定义的Applet子类中,一般需要重载父类的( D )方法来完成一些画图操作。

  A. start() B. stop()

  C. init() D. paint()

  3、Java语言具有许多优点和特点,下列选项中,哪个反映了Java程序并行机制的特点?B

  A)安全性 B)多线程 C)跨平台 D)可移植

  4、下列哪个类声明是正确的?D

  A)abstract final class HI{···} B)abstract private move(){···}

  C)protected private number; D)public abstract class Car{···}

  6、在Java语言中,下列哪些语句关于内存回收的说明是正确的? B

  A.程序员必须创建一个线程来释放内存;

  B.内存回收程序负责释放无用内存

  C.内存回收程序允许程序员直接释放内存

  D.内存回收程序可以在指定的时间释放内存对象

  10、下列Object类中的方法,哪一项不是完全跟线程有关: A

  A.String toString()

  B.void notify()

  C.void notifyAll()

  D.void wait()

  11、给出下面代码:C

  public class Person{

  static int arr[] = new int[10];

  public static void main(String a[])

  {

  System.out.println(arr[1]);

  }

  }

  下列说法中正确的是?

  A.编译时将产生错误;

  B.编译时正确,运行时将产生错误;

  C. 输出零;

  D. 输出空。

  12、字符串是Java已定义的类型,关于它的构造函数,下面说法不正确的是: B

  A.String(char[] value, int offset, int count)

  B.String(int[] codePoints,int offset, int count)

  C.String(String original)

  D.String(StringBuffer buffer)

  13、下列说法中正确的是: C

  A.导入包会影响程序的性能

  B.包存储在类库中

  C.包是类的容器D.上述说法都不对

  14、下列不是String类的常用方法是:C

  A、boolean equals(String str)

  B、int compareTo(String str)

  C、int SetindexOf(String str)

  D、int lastIndexOf(String str)

  17、表达式:(x>y) ? (z>w) ?x:z:w,(其中x=5,y=9,z=1,w=9)的值为:D

  A、5 B、8

  C、1 D、9

  1、main方法是Java Application程序执行的入口点,关于main方法的方法头以下哪项是合法的( B)?

  A、public static void main( )

  B、public static void main( String args[] )

  C、public static int main(String [] arg )

  D、public void main(String arg[] )

  5、欲构造ArrayList类的一个实例,下列哪个方法是正确的 ? B

  A. ArrayList myList=new Object();

  B. ArrayList myList=new ArrayList();

  C. myList= new Object();

  D. myList= new ArrayList();

  7、哪个关键字可以对对象加互斥锁? B

  A.transient

  B.synchronized

  C.serialize

  D.static

  9、下列叙述中,错误的是: D

  A、父类不能替代子类

  B、子类能够替代父类

  C、子类继承父类

  D、父类包含子类

  10、下列关于Java多线程并发控制机制的叙述中,错误的是:BC

  A、Java中对共享数据操作的并发控制是采用加锁技术

  B、线程之间的交互,提倡采用suspend()/resume()方法

  C、共享数据的访问权限都必须定义为private

  D、Java中没有提供检测与避免死锁的专门机制,但应用程序员可以采用某些策略防止死锁的发生

  12、下列哪一个方法不是applet程序的组成部分:D

  A、init() B、start()

  C、stop() D、new()

  15、Java应用程序中,程序执行的总入口方法是:B

  A、start() B、main()C、run() D、init()

  16、在Java实现线程有多少种方法:B

  A、1 B、2

  C、3 D、4

  18、下列Applet类的方法中,在Applet的整个生命周期里至多只执行一次的是:A

  A、init() B、start()

  C、stop() D、paint()

  19、启动一个线程所调用的方法是:C

  A、run() B、init()

  C、start() D、new()

  判断题

  1.一个Java类可以有多个父类。

  4.Java小程序Applet的主类的父类必须是类Applet。

  5.break语句可以用在循环和switch语句中。

  6.在Java中,异常Exception是指程序在编译和运行进出现的错误。

  7.可以用new来创建一个类的实例,即对象。

  8.Java使用16位的Unicode字符集,而不仅仅为ASCII字符集,因此Java字符是一个16位的无符号整数。

  10.子类的成员变量能与其父类的`成员变量同名。

  11.Java类中不能存在同名的两个成员函数。

  12.Java语言是编译性语言。

  16.final方法不能被覆盖。

  20.多数I/O方法在遇到错误是会抛出异常,因此在调用这些方法时必须对异常进行处理。

  2.abstract 是抽象修饰符,可以用来修饰类及其属性和方法。

  4.一个Java Applet源程序的主类能有多个父类。

  6.用javac编译Java源文件后得到代码叫字节码。

  7.可以用类名调用实例方法。

  9.要想在类中实现多线程,类必须继承Thread类。

  11.Java语言是平台无关的语言。

  12.在类的静态方法中可以访问该类的非静态数据成员。

  13.Java中方法调用时参数传递都是按值传递的,因此从方法退出时,参数的值不会改变。

  14.声明为final的方法不能在子类中重载。

  15.在子类中可以覆盖一个private方法。

  19.在方法定义中,所有可能发生的异常都必须用try{}catch(){}捕捉并处理

  1.请写出输出结果

  class change{

  void changeint(int x){

  x++;

  } public static void main(String args[]){

  int a=2;

  System.out.println("Before changed: "+"a="+a); //请系统输出Before changed: a=

  change cxz=new change();

  cxz.changeint(a);

  System.out.println("After changed: "+"a="+a);

  }

  }

  答案:

  Before changed: a= 2

  After changed: a= 3

  2. 下面程序运行的最终结果i是:___2_____

  public class Foo {

  public static void main (String []args) {

  int i = 1;

  int j = i++;

  if ((i>++j) && (i++ ==j)) {

  i +=j;

  }

  }

  }

  3、阅读以下程序,请写出输出结果

  import java.lang.*;

  public class StrCompare

  {

  public static void main(String[] args)

  {

  String

  str1 = "Hello, Java!",

  str2 = "hello, java!";

  System.out.println(str1.compareToIgnoreCase(str2));

  System.out.println(str1.equals(str2)); System.out.println(str1.equalsIgnoreCase(str2)); }

  }

  答:

  0

  False

  True

  4、阅读以下程序,请写出输出第一行结果

  public class abc

  {

  public static void main(String args[ ])

  { int i =3,j ;

  while (i>0){

  j=3;

  while (j>0){ if (j<2)

  break;

  System.out.println(

  "j+and"+i);

  j--;

  }

  i--;

  }

  }

  }

  答:

  j+and3

  j+and3

  j+and2

  j+and2

  j+and1

  j+and1

  5、 import java.io.*;

  public class abc

  { public static void main(String args[ ])

  { AB s = new AB("Hello!","I love JAVA.");

  System.out.println(s.toString( ));

  }

  }

  class AB {

  String s1;

  String s2;

  AB( String str1 , String str2 )

  { s1 = str1; s2 = str2; }

  public String toString( )

  { return s1+s2;}

  }

  答:

  Hello!I love JAVA.

  6、阅读以下程序,请写出输出c.x=是多少

  public class withstaticdata {

  static int x;

  int y;

  public static void main(String[] args) {

  withstaticdata a=new withstaticdata();

  a.x=1;

  System.out.println(a.x);withstaticdata b=new withstaticdata();

  b.x=2;

  System.out.println(b.x); System.out.println(a.x); withstaticdata c=new withstaticdata();

  System.out.println(

  "c.x="+c.x); }

  }

  答:2

  public class StaticFun {

  static void incr(){

  withstaticdata.x++

  ;

  }

  public static void main( String [] args )

  {

  StaticFun.incr();

  }

  }

  1、在横线上填上适当的内容

  import java.awt.*;

  import java.applet.*;

  public class AppletLife extends Applet //声明为Apple类

  {

  Color r;

  public AppletLife() //初始化

  {

  System.out.println("Applet initing...");

  r = Color.red;

  }

  public void start()

  {

  System.out.println("Applet starting...");

  }

  public void stop()

  {

  System.out.println("Applet stopping...");

  }

  public void paint(Graphics g)

  {

  System.out.println("Applet painting...");

  g.setColor(r);

  g.drawString("Painting here!", 50, 60 );

  }

  public void destroy()

  {

  System.out.println("Applet destroy...");

  }

  }

  2. 阅读以下程序,请写出输出结果

  public class tt {

  public static void main(String[] args) {

  String s=new String("Bicycle");

  int iBegin=1;

  int iEnd=3;

  System.out.println(s.substring(iBegin,i

  End));}

  }

  答:ic

  3、请在相应的划线上填上代码

  public class CircumferenceTester {

  public static void main(String args[]) {

  Circle c1 = new Circle();

  c1.radius = 50;

  Circle c2 = new Circle();

  c2.radius = 10;

  double circum1 = c1.circumference();

  double circum2 = c2.circumference();

  System.out.println(

  "Circle 1 has circumference " + circum1);

  System.out.println(

  "Circle 2 has circumference " + circum2);

  }

  }

  public class Circle

  {

  private static double PI = 3.141; //静态double 常量PI为 3.141

  int radius;

  public double circumference()

  {

  return 2*PI*radius;

  }

  public double area()

  {

  return PI * radius * radius;

  }

  public void enlarge(int factor) {

  radius = radius * factor;

  }

  public boolean fitsInside (Rectangle r) {

  return (2 * radius < r.width) && (2 * radius < r.height);

  }

  }

  4、阅读以下程序,请写出输出结果

  class father{

  void speak(){

  System.out.println(

  "I am father!");

  }

  }

  public class son extends father{

  void speak(){

  super.speak();

  System.out.println(

  "I am son!");

  }

  public static void main(String args[]){

  son cxz=new son();

  cxz.speak();

  }}

  答:

  I am father!

  I am son!

  5.写出下面程序的运行结果

  import java.io.*;

  class Parent

  {

  void printMe()

  {

  System.out.println("parent");

  }

  }

  class Child extends Parent

  {

  void printMe()

  {

  System.out.println("child");

  }

  void printAll()

  {

  super.printMe();

  this.printMe();

  printMe();

  }

  }

  public class Class1

  {

  public static void main(String args[ ])

  {

  Child myC = new Child( );

  myC.printAll( );

  }

  }

  答:

  parent

  child

  child

  6.写出下面程序的运行结果

  import java.io.*;

  public class abc

  {

  public static void main(String args[])

  {

  String s1 = "Hello!";

  String s2 = new String("World!");

  System.out.println(s1.concat(s2));

  } }

  答:

  Hello!World!定义能计算圆的面积、周长的类circle,半径r为私有数据分量,其值由类circle的构造函数初始化,类circle提供读取半径r的方法getr();计算面积的方法area();计算周长的方法circlelength()。再定义类circlecomputer其包含程序运行所需的方法main,圆的半径为1,请设计程序, 必须使用类circle的构造函数及方法初始化数据分量和计算圆的面积、周长并打印出如下形式的结果。

  半径 面积 周长

  答:public

  class circle {

  private int r;

  private static double PI = 3.141;

  public circle(int r) {

  this.r = r;

  }

  public int getR() {

  return r;

  }

  public double area() {

  return PI * r * r;

  }

  public double circlelength() {

  return 2 * PI * r;

  }

  }

  public class circlecomputer {

  public static void main(String[] args) {

  circle c = new circle(1);//

  实例化

  circle

  并设置半径为

  1

  System.out.println("

  半径 面积 周长

  ");

  System.out.print(c.getR());

  System.out.print(" ");

  System.out.print(c.area());System.out.print(" ");

  System.out.print(c.circlelength());

  }

  }定义能

  计算三角形的面积、周长的类js,三边a,b,c都为私有数据分量,其值由类sj的构造函数初始化,类js提供读取各边长度a,b,c的方法分别为geta(); getb(); getc(); 计算面积的方法area();计算周长的方法sjlength()。

  (三角形面积公式:c)

  -b)(s-a)(s-s(s 其中s=(a+b+c)/2)

  再定义类jxcomputer其包含程序运行所需的方法main,矩三角形的三边a为3,b为6,c为8请设计程序必须使用类sj的构造函数及方法初始化数据分量和计算的三角形的面积、周长并打印出如下形式的结果。

  a b c 面积 周长

  答:public

  class js {

  private int a;

  private int b;

  private int c;

  public js(int a, int b, int c) {

  this.a = a;

  this.b = b;

  this.c = c;

  }

  public int getA() {

  return a;

  }

  public int getB() {

  return b;

  }

  public int getC() {

  return c;

  }

  public double area() {

  double s = this.s();return Math.sqrt(s * (s - a) * (s - b) * (s - c));

  }

  public double sjlength() {

  return a + b + c;

  }

  public double s() {

  return this.sjlength() / 2;

  }

  }

  import java.text.DecimalFormat;

  public class jxcomputer {

  public static void main(String[] arg) {

  js j = new js(3, 6, 8);

  System.out.println("a b c

  面积 周长

  ");

  System.out.print(j.getA());

  System.out.print(" ");

  System.out.print(j.getB());

  System.out.print(" ");

  System.out.print(j.getB());

  System.out.print(" ");

  DecimalFormat df = new DecimalFormat("#.00"); //

  保留两位小数,此句可以不用

  System.out.print(df.format(j.area()));

  System.out.print(" ");

  System.out.print(j.sjlength());

  }

  }

【java考试习题及答案】相关文章:

1.java习题及答案

2.计算机二级考试Java备考复习题及答案

3.2016年Java考试精选练习题及答案

4.Java考试格林练习题

5.Java考试格林模拟习题

6.java认证考试试题及答案

7.Sun java认证考试真题答案

8.2016年java考试试题及答案