javaPTA期末复习


一、判断题

1-1static关键字可以修饰成员变量,也可以修饰局部变量。 (1分) F
2、可以覆盖在父类中定义的私有方法。 F
3、package语句必须放到java程序的最开始。 T
4、Java的字符类型采用的是Unicode编码,每个Unicode码占16个比特。 T
5、对于abstract类,不能创建该类的对象。 (1分) T
6、可以使用protected修饰符来防止方法和数据被不同包的非子类访问。 (1分) T
7、类及其属性、方法可以同时有一个以上的修饰符来修饰。 (1分) T
8、可以使用protected修饰符来防止方法和数据被不同包的非子类访问。(1分) T
9、static关键字可以修饰成员变量,也可以修饰局部变量。 F
10、可以覆盖在父类中定义的私有方法。 F
11、构造方法可以调用本类中重载的构造方法和它的父类的构造方法。 T
12、子类不继承父类的构造方法。 T
13、可以使用protected修饰符来防止方法和数据被不同包的非子类访问。 T
考前练习1
14、static关键字可以修饰成员变量,也可以修饰局部变量。 F
15、静态变量是被同一个类的所有实例所共享的。 T
16、对象是类的实例(instance)。 T
17、类也是一种数据类型(type)。 T
18、An interface can extend an abstract class. F
19、You can always successfully cast an instance of a superclass to a subclass. 您始终可以成功地将超类的实例强制转换为子类。 F
20、A protected datum or method can be accessed by any class in the same package.。 T
21、An abstract class can be extended. T
考前练习2
22、HashSet类是线程不安全的。 T
23、StringBuffer类是线程安全的,StringBuilder类是线程不安全的。 T
24 、A protected datum or method can be accessed by any class in the same package.。 T
25、ArrayList类是线程安全的。 F
26、A wrapper is used when you want to treat a primitive like an object.当你想把一个原语当作一个对象来处理时,就使用一个包装器。 T
27、

二、选择题

1、在Java中,负责对字节代码解释执行的是 ( ) (2分)
应用服务器
虚拟机
垃圾回收器
编译器
2、编译和运行下列程序会出现什么样的结果( )。 (2分)

public class Ref {	
       public static void main(String[] args){
             Ref r = new Ref();
             r.amethod(r);
       }
       public void amethod(Ref r){
             int i = 99;
             multi(r);
       System.out.println(i);
       }
       public void multi(Ref r){
             r.i = r.i * 2;
       }
}

编译出错
输出:99
输出:198
运行出错
3、非静态内部类,有时也称为实例内部类或成员内部类,它具有以下特点,除了( )。 (2分)
在创建非静态内部类的实例时,外部类的实例不是必须存在
非静态内部类的实例自动持有外部类的实例引用
外部类实例和内部类实例之间是一对多的关系
一个内部类实例只会引用一个外部类实例
4、下面哪个函数是public void aMethod(){…}的重载函数?( ) (2分)
void aMethod( ){…}
public int aMethod(){…}
public void aMethod ( ){…}
public int aMethod ( int m){…}
5、若在某一个类定义中定义有如下的方法:abstract void performDial( );该方法属于( )。(2分)
接口方法
最终方法
抽象方法
空方法
6、 Which keyword is used to make a class definition
include the non-private attributes and behaviors of
a parent class, as well as additional attributes and
behaviors that are specific to the class being defined?
分值为2分。 (2分)使用哪个关键字来定义类包括 父类,以及其他属性和 特定于所定义类的行为?
extends
super
inheritance
finalizer
7、下面哪一句是关于非静态的内部类正确的描述? (2分)
It must implement an interface.
It can access private instance variables in the enclosing object. 它可以访问封闭对象中的私有实例变量。
It is accessible from any other class.
It can only be instantiated in the enclosing class.
It must be final if it is declared in a method scope.
8、
2-1 java中,负责对字节代码解释执行的是 ( 虚拟机) (2分)
2-2 Java程序默认引用的包是( java.lang包 )。 (2分)
[解析] java.lang包提供Java编程语言进行程序设计的基础类。java.lang包是编译器自动导入的2
2-3 下列关于System类的叙述中,错误的是( C)。 (2分)
A .System类是一个final类
B.System类不能实例化
C. System类中没有定义属性
D. System类主要提供了系统环境参数的访问
[解析] 本题考查System类的基本知识。System类是一个final类,所有的方法都用类变量来调用,对System类不可能实例化。System类主要用来提供标准输入/输出和系统环境信息的访问设置。而System类的属性有:①public static final InputStream in;标准输入,②public static final OutputStream out;标准输出,③public static final PrintStreamerr;标准错误输出。
2-4在面向对象的软件系统中,不同类对象之间的通信的一种构造称为_。(D) (2分)
A. 属性
B .封装
C. 类
D. 消息
考前练习2
9、A JavaFX action event handler contains a method __. (2分)
public void actionPerformed(ActionEvent e)
public void handle(Event e)
public void actionPerformed(Event e)
public void handle(ActionEvent e)
10、A JavaFX action event handler is an instance of _.(2分)
EventHandler< ActionEvent>
EventHandler
ActionEvent
Action
11、A JavaFX event handler for event type T is an instance of _. (2分)
EventHandler < T >
ActionEvent
Action
EventHandler

12、To handle the mouse click event on a pane p, register the handler with p using __. (2分)
p.setOnMouseClicked(handler);

p.setOnMouseReleased(handler);
p.setOnMouseDragged(handler);
p.setOnMousePressed(handler);
13、 Suppose A is an anonymous inner class in Test. A is compiled into a file named _. (2分)
A.class
Test A . c l a s s A A.class A A.classATest.class
Test$1.class

Test&1.class
考前练习4
14、如果需要从文件中读取数据,则可以在程序中创建哪一个类的对象()。 (2分)
FileInputStream
FileOutputStream
DataOutputStream
FileWriter
15、Which of the following computer components are referred to as hardware?
分值为2分。 (2分)
monitor, keyboard, and programs
mouse, CPU, and programs
monitor, CPU, and keyboard
keyboard, programs, and mouse
16、What kind of reader do you use to handle Character code? ( ) (2分)
Reader
Writer
PrintWriter
InputStreamReader
17、Object of which class below can be real parameter (参数)of constructor of DataInputStream?( ) (2分)
File
String
FilterInputStream
FileOutputStream
考前练习5
18、以下哪个关键字可以用来给对象加互斥锁?( ) (2分)
transient
synchronized
serialize
static
19、 Which method you define as the starting point of new thread in a class from which new the thread can be excution? ( ) (2分)
public void start()
public void run()
public void int()
public static void main(String args[])
20、下列哪个一个操作不能使线程从等待阻塞状态进入对象阻塞状态( )。 (2分)
等待阻塞状态下的线程被notify()唤醒
等待阻塞状态下的纯种被interrput()中断
等待时间到
等待阻塞状态下的线程调用wait()方法
21、下列说法中错误的一项是( )。 (2分)
一个线程是一个Thread类的实例。
线程从传递给纯种的Runnable实例run()方法开始执行。
新建的线程调用start()方法就能立即进入运行状态。
线程操作的数据来自Runnable实例
22、以下哪个关键字可以用来给对象加互斥锁?( ) (2分)
transient
synchronized
serialize
static
练习1
23、在Java中,负责对字节代码解释执行的是 ( ) (2分)
应用服务器
虚拟机
垃圾回收器
编译器
24、 Java程序默认引用的包是( )。 (2分)
java.text包
java.awt包
java.lang包
java.util包
25、下列关于System类的叙述中,错误的是( )。 (2分)
System类是一个final类
System类不能实例化
System类中没有定义属性
System类主要提供了系统环境参数的访问
26、 在面向对象的软件系统中,不同类对象之间的通信的一种构造称为_。 (2分)
属性
封装

消息
27、在面向对象方法中,继承定义了超类和子类的概念,子类在维持原有父类中方法签名不变的前提下,用适合于自己要求的实现去置换父类中的相应方法的实现称为__。 (2分)
继承
覆盖(overriding)
重载(overloading)
多态
28、以下哪句是错误的? (2分)
编译器会搜索要import的类的编译结果文件而不是源文件
import是告诉编译器要import的包的信息
import是把要import的类的源代码插入到import语句所在的地方
编译器在编译的时候需要能访问得到要import的类的编译结果文件
29、 下面哪一个描述是正确的? (2分)
Node对象可以被放置在 Scene中.
Node对象可以被放置在 Pane中.
Shape 对象可以被放置在Control中.
Pane对象可以被放置在Control中.

30、为了从pane中删除两个节点 node1和node2 ,使用下面哪一个语句 __. (2分)
pane.removeAll(node1, node2);
pane.remove(node1, node2);
pane.getChildren().removeAll(node1, node2);
pane.getChildren().remove(node1, node2);
31、为了在BorderPane p的左部放置一个node对象, 使用下面哪一个语句 _. (2分)
p.setLeft(node);
p.placeLeft(node);
p.left(node);
p.setEast(node);
32、声明并创建一个按钮对象b,应该使用的语句是( ) (2分)
Button b=new Button( );
button b=new button( );
Button b=new b( );
b.setLabel(“确定”);


三、程序填空题

1、相同的数组。如果两个数组list1和list2的内容相同,那么就说它们是相同的。使用下面的程序可以判断两个数组是否相同,请填空补全程序。

import java.util.*;
public class Main {
   public static void main(String[] args) {
      Scanner input = new Scanner(System.in);
      int size1 = input.nextInt();
      int[] list1 = new int[size1];
      // Enter values for list1
      for (int i = 0; i < list1.length; i++)
         list1[i] = input.nextInt();
      int size2 = input.nextInt();
      int[] list2 = new int[size2];
      // Enter values for list2
      for (int i = 0; i < list2.length; i++)
         list2[i] = input.nextInt();
      input.close();
      if (equals(list1,list2)     (4)) {
         System.out.println("Two lists are identical");
      } else {
         System.out.println("Two lists are not identical");
      }
   }
   public static boolean equals(int[] list1, int[] list2) {
      if (list1.lenth!=list2.length          (3))
         return false;
      Arrays.sort(list1);
      Arrays.sort(list2)           (3);
      for (int i = 0; i < list1.length; i++)
         if (list1[i] != list2[i])
            return false;
      return true;
   }
}

2、(检验密码)一些网站设定了一些制定密码的规则。编写一个方法,检验一个字符串是否合法的密码。假设密码规则如下: 密码必须至少有8个字符。 密码只能包含字母和数字。 密码必须至少有2个数字。 请编写一个程序,提示用户输入密码,如果改密码符合规则就显示“Valid password”,否则显示“Invalid password”。

public class Main {
	  public static void main(String[] args) {
	    // Prompt the user to enter a password
	    java.util.Scanner input = new java.util.Scanner(System.in);
	    //System.out.print("Enter a string for password: ");
	    String s = input.nextLine();
	    if (  isValidPassword(s)           (3)) {
	      System.out.println("Valid password");
	    }
	    else {
	      System.out.println("Invalid password");
	    }
	  }
	  /** Check if a string is a valid password */
	  public static boolean isValidPassword(String s) {
	    // Only letters and digits?
	    for (int i = 0; i < s.length(); i++) {
	      if (!Character.isLetter(password.charAt(i)) ((3)) && 
	          !Character.isDigit(s.charAt(i)))
	        return false;
	    }
	    
	    // Check length
	    if ( s.length()            (2) < 8)`在这里插入代码片`
	      return false;
	    
	    // Count the number of digits
	    int count = 0;
	    for (int i = 0; i < s.length(); i++) {
	      if ( Character.isDigit(s.charAt(i))        (2))
	        count++;
	    }
	    
	    if (count >= 2)
	      return true;
	    else 
	      return false;
	  }
	}

考前练习1
3、Once it is created, an array is (2分).
If your application does not require the (2分) or deletion of elements, an array is the most (2分) data structure.

4、In JavaFX application,stage is a (2分) for displaying a scene that contains nodes.
5、A main JavaFX class must extend (2分) and implement the (2分) method. The primary (2分) is automatically created by the JVM and passed to the start method.
考前练习3
6、阅读下列说明和Java代码,并填空。
【说明】现欲构造一文件/目录树,采用组合(Composite)设计模式来设计,得到的类图如下图所示:

在这里插入图片描述

import java.util.ArrayList;
import java.util.List;

abstract      (2) class AbstractFile {
	protected String name;

	public void printName() {
		System.out.println(name);
	}

	public abstract boolean addChild(AbstractFile file);

	public abstract boolean removeChild(AbstractFile file);

	public abstract List<AbstractFile> getChildren();
}

class File extends AbstractFile {
	public File(String name) {
		this.name = name;
	}

	public boolean addChild(AbstractFile file) {
		return false;
	}

	public boolean removeChild(AbstractFile file) {
		return false;
	}

	public List<AbstractFile> getChildren() {
		return     null         (2);
	}
}

class Folder extends AbstractFile {
	private List<AbstractFile> childList;

	public Folder(String name) {
		this.name = name;
		this.childList = new ArrayList<AbstractFile>();
	}

	public boolean addChild(AbstractFile file) {
		return childList.add(file);
	}

	public boolean removeChild(AbstractFile file) {
		return childList.remove(file);
	}

	public List           (2)<AbstractFile> getChildren() {
		return   childList              (2);
	}
}

public class Main {
	public static void main(String[] args) {
		// 构造一个树形的文件/目录结构
		AbstractFile rootFolder = new Folder("root");
		AbstractFile compositeFolder = new Folder("composite");
		AbstractFile windowsFolder = new Folder("windows");
		AbstractFile file = new File("TestComposite.java");
		compositeFolder.addChild(file);
		rootFolder.addChild(compositeFolder);
		rootFolder.addChild(windowsFolder);

		// 打印目录文件树
		printTree(rootFolder);
	}

	private static void printTree(AbstractFile ifile) {
		ifile.printName();
		List<AbstractFile> children = ifile.getChildren();
		if (children == null)
			return;
		for (AbstractFile file : children) {
			file.printName()      (2);
		}
	}
}

考前练习4
7、相同的数组。如果两个数组list1和list2的内容相同,那么就说它们是相同的。使用下面的程序可以判断两个数组是否相同,请填空补全程序。

import java.util.*;
public class Main {
   public static void main(String[] args) {
      Scanner input = new Scanner(System.in);
      int size1 = input.nextInt();
      int[] list1 = new int[size1];
      // Enter values for list1
      for (int i = 0; i < list1.length; i++)
         list1[i] = input.nextInt();
      int size2 = input.nextInt();
      int[] list2 = new int[size2];
      // Enter values for list2
      for (int i = 0; i < list2.length; i++)
         list2[i] = input.nextInt();
      input.close();
      if ( equals(list1,list2)        (4)) {
         System.out.println("Two lists are identical");
      } else {
         System.out.println("Two lists are not identical");
      }
   }
   public static boolean equals(int[] list1, int[] list2) {
      if ( list1.length!=list2.length        (3))
         return false;
      Arrays.sort(list1);
      Arrays.sort(list1);                 (3);
      for (int i = 0; i < list1.length; i++)
         if (list1[i] != list2[i])
            return false;
      return true;
   }
}

8、

  • 12
    点赞
  • 110
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值