致谢:感谢@WalkingWithTheWind~帮我寻找PTA中的CSS选择器
-
For code below:
Loop1:
while ( true ) { // 1
for ( ; true; ) {
if ( i ==2 )
break Loop1; // 2
}
i=4; // 3
}
i=5; // 4
After executing line 2, where will the program jump to? 1.1
答案:
1.1: 4
答案正确 -
给出以下代码:
class Number {
int i;
public Number(int ii) { i=ii; }
}
public class Main {
public static void main(String[] args) {
Number[] a = new Number[5];
for ( int i=0; i<a.length; i++ ) a[i] = new Number(i);
for ( int i=0; i<2; i++ )
for ( Number n : a ) {
System.out.print(n.i);
n.i = 5-n.i;
}
}
}
程序运行结果是: 2.1
答案:
2.1: 0123454321
答案正确 -
给出以下代码:
public class Test {
public int t=4;
public static void main(String[] args) {
new Test().NumberPlay();
}
public void NumberPlay() {
int t=2;
t = t+5;
this.t = this.t-2;
t = t-this.t;
System.out.println(t+this.t+“ok”);
}
}
程序运行后输出结果为: 3.1
答案:
3.1: 7ok
答案正确 -
请说出A类中System.out.println的输出结果。
class B{
int x=100,y=200;
public void setX(int x){ x=x; }
public void setY(int y){ this.y=y; }
public int getXYSum(){ return x+y; }
}
public class A {
public static void main(String args[]){
B b=newB();
b.setX(-100);
b.setY(-200);
System.out.println(“sum=”+b.getXYSum());
}
}
程序输出结果为:sum= 4.1
答案:
4.1: -100
答案正确 -
For a class Class1 in Class1.java as below:
package Testpackage;
public class Class1{
… …
}
The main() is in MainPro.java as below:
import Testpackage.*;
… …
The CLASSPATH is "c:\java\lib\classes.zip;.; ". The MainPro.java is in c:\Testdir. The current directory is c:\Testdir. Where should we put the Class1.class? 5.1
答案:
5.1: c:\Testdir\Testpackage
答案正确 -
对于java.io包中的所有I/O类,根据数据流所关联的是数据源还是其他数据流,可分为节点流和 6.1
。
答案:
6.1: 处理流
答案正确 -
7.1
类实现了缓存功能的InputStream。
答案:
7.1: BufferedInputStream
答案正确 -
请写出以下程序运行结果:
public class MyFor{
public static void main(String argv[]){
int i, j;
outer: for (i=1;i<3;i++)
inner: for (j=1; j<3; j++) {
if (j==2)continue outer;
System.out.println(“Value for i=” + i + " Value for j=" +j);
}
}
} 8.1 8.2
答案:
8.1: Value for i=1 Value for j=1
8.2: Value for i=2 Value for j=1
答案正确 -
阅读以下程序:
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int number, max;
number = input.nextInt();
max = number;
while (number != 0) {
number = input.nextInt();
if (number > max)
max = number;
}
System.out.println("max is " + max);
System.out.println("number " + number);
}
}
假设输入是 2 3 4 5 0,程序输出是:
max is 9.1
number 9.2
答案:
9.1: 5
9.2: 0
答案正确
-
请写出以下程序运行结果:
class A
{
int x;
String s;
};
class HelloWorld
{
public static void main(String[] args)
{
A a= new A();
System.out.println(a.s);
System.out.println(a.x);
}} 10.1 10.2
答案:
10.1: null
10.2: 0
答案正确 -
Java的三大体系分别是封装、( )、( )。 11.1 11.2
答案:
11.1: 多态
11.2: 继承
答案正确 -
定义在类中的变量被称为( ),定义在方法中的变量被称为( )。 12.1 12.2
答案:
12.1: 成员变量
12.2: 局部变量
答案正确 -
阅读以下程序,在空格内填上正确答案。
public class Test {
public static void main(String[] args) {
int number = 0;
int[] numbers = new int[1];m(number, numbers);
System.out.println("number is " + number+ " and numbers[0] is " + numbers[0]);
}
public static void m(int x, int[] y) {
x = 3;
y[0] = 3;
}
}
程序运行后,输出:
number is 13.1
and numbers[0] is 13.2
答案:
13.1: 0
13.2: 3
答案正确 -
在Java程序中,创建一个包即打包操作,应使用关键词 14.1
,该关键词引导的语句必须放在程序的第 14.2
行,该行前只能有空格及注释。
在Java程序中,想要导入不同包下面的某个类时,可以使用关键词 14.3
。
答案:
14.1: package
14.2: 1
14.3: import
答案正确 -
阅读以下程序,写出输出结果。
public class AppleMobilePhone extends MobilePhone{
public static void main(String[] args){
new AppleMobilePhone();
}
public AppleMobilePhone(){
System.out.println(“This is a Applemobilephone”);
}
}
class MobilePhone extends Phone{
public MobilePhone(){
System.out.println(“This is a mobilephone”);
}
}
class Phone{
public Phone(){
System.out.println(“This is a phone”);
}
}
程序运行后输出: 从下列选项中选,在空格处填上相应的序号数字(1、2或3)
(1)This is a phone
(2)This is a Apple mobile phone
(3)This is a mobile phone
第一行输出: 15.1
第二行输出: 15.2
第三行输出: 15.3
答案:
15.1: 1
15.2: 3
15.3: 2
答案正确 -
说出下列A类中【代码1】~【代码3】的输出结果
class Fish { int weight=1; }
class Lake{
Fish fish;
void setFish(Fish s) { fish=s; }
void foodFish(int m){ fish.weight=fish.weight+m; }
}
public class Main {
public static void main(String args[]){
Fish redFish=new Fish();
System.out.println(redFish.weight);//【代码1】
Lake lake=new Lake();
lake.setFish(redFish);
lake.foodFish(120);
System.out.println(redFish.weight);//【代码2】
System.out.println(lake.fish.weight);//【代码3】
}
}
【代码1】 16.1
【代码2】 16.2
【代码3】 16.3
答案:
16.1: 1
16.2: 121
16.3: 121
答案正确 -
阅读下列程序:
class A{
int i=7;
public A(){
setI(20);
System.out.println(“i=”+i);
}
public void setI(int i){
this.i=2i;
}
}
class B extends A{
public B(){
System.out.println(“i=”+i);
}
public void setI(int i){
this.i=3i;
}
}
public class Main{
public static void main(String[] args){
new A();
new B();
}
}
程序运行后依次输出: 17.1 17.2 17.3
答案:
17.1: i=40
17.2: i=60
17.3: i=60
答案正确 -
阅读以下程序:
public class Test extends TT{
public static void main(String args[]){
Test t=new Test(“Tom”);
}
public Test(String s){
super(s);
System.out.println(“How do you do?”);
}
public Test(){
this(“I am Tom”);
}
}
class TT {
public TT(){
System.out.println(“What a pleasure!”);
}
public TT(String s){
this();
System.out.println("I am "+s);
}
}
程序运行结果为: 18.1 18.2 18.3
答案:
18.1: What a pleasure!
18.2: I am Tom
18.3: How do you do?
答案正确 -
请写出以下程序运行结果:
class Exception1 extends Exception {}
class Exception2 extends Exception1 {}
public class Test {
public static void main(String[] args)
throws Exception {
try {
try {
throw new Exception2();
} catch ( Exception1 a ) {
System.out.println(“Caught Exception1”);
throw a;
}
} catch ( Exception2 s ) {
System.out.println(“Caught Exception2”);
return ;
} finally {
System.out.println(“Hello World!”);
}}} 19.1 19.2 19.3
答案:
19.1: Caught Exception1
19.2: Caught Exception2
19.3: Hello World!
答案正确 -
访问父类的成员可以使用 20.1
关键字。
答案:
20.1: super
答案正确 -
给出以下代码:
class Number {
public int i;
public Number(int ii) {i=ii;};
}
public class Main {
static void f(Number n) {
n.i = 9;
}
static void g(Integer n) {
n=9;
}
public static void main(String[] args) {
Number k = new Number(10);
f(k);
Integer m = new Integer(10);
g(m);
System.out.println(k.i+":"+m);
}
}
程序运行后输出结果是: 21.1
答案:
21.1: 9:10
答案正确 -
用 22.1
关键字修饰的类不能被继承。
答案:
22.1: final
答案正确 -
请写出以下程序运行结果:
class Letter {
char c;
}
public class Main {
static void f(Letter y) {
y.c = ‘z’;
}public static void main(String[] args) {
Letter x = new Letter();
x.c = ‘a’;
f(x);
System.out.println(x.c);
}
} 23.1
答案:
23.1: z
答案正确 -
下列代码的运行结果是什么?
public class Main{
static{
System.out.print(“Hi here,”);
}
public void print(){
System.out.print(“Hello”);
}
public static void main(String args[]){
Main m1=new Main();
m1.print();
Main m2=new Main();
m2.print();
}
}
上述代码的运行结果为: 24.1
答案:
24.1: Hi here,HelloHello
答案正确 -
接口中的方法的默认的访问权限是 25.1
。
答案:
25.1: public
答案正确 -
请写出以下程序运行结果:
public class X {
public static void main(String [] args) {
try {
badMethod();
System.out.print(“A”);
} catch (RuntimeException ex) {
System.out.print(“B”);
} catch (Exception ex1) {
System.out.print(“C”);
} finally {
System.out.print(“D”);
}
System.out.print(“E”);
}
public static void badMethod() {
throw new RuntimeException();
}} 26.1
答案:
26.1: BDE
答案正确 -
在Java中, 27.1
类是所有异常和错误的顶级父类。
答案:
27.1: Throwable
答案正确 -
给出以下代码:
public class Main {
int i=0;
Main(int ii) { i = ii; }
Main(String s) { this(s.length()); }
public String toString() { return String.format("%02X",i); }
public static void main(String[] args) {
Main m = new Main(“hello world”);
System.out.println(m);
}
}
程序运行输出结果是: 28.1
答案:
28.1: 0B
答案正确 -
当编译并运行下列代码时,其运行结果是什么?
public class Main{
public static void main(String args[]){
String s=“Java”;
StringBuffer sb=new StringBuffer(“Java”);
change(s);
change(sb);
System.out.println(s+sb);
}
public static void change(String s){
s=s.concat(“Hello”);
}
public static void change(StringBuffer sb){
sb.append(“Hello”);
}
}
上述代码的运行结果为: 29.1
答案:
29.1: JavaJavaHello
答案正确 -
当编译并运行下列代码时,其运行结果时什么?
public class Main{
public static void main(String args[]){
String s=“Java”;
StringBuffer sb=new StringBuffer(“Java”);
hello(sb,s);
System.out.println(sb+s);
}
public static void hello(StringBuffer sb, String s){
sb.append(“A”);
s=sb.toString();
}
}
上述代码的运行结果为: 30.1
答案:
30.1: JavaAJava
答案正确 -
当编译并运行下列代码时,其运行结果是什么?
public class Main{
public static void main(String args[]){
certkiller(“four”);
certkiller(“tee”);
certkiller(“to”);
}
public static void certkiller(String str){
int check=4;
if(check==str.length())
System.out.print(str.charAt(check-=1));
else
System.out.print(str.charAt(0));
}
}
上述代码的运行结果为: 31.1
。
答案:
31.1: rtt
答案正确 -
当编译并运行下列代码时,其运行结果是什么?
public class Main{
public static void main(String args[]){
String s=“Hello”;
methodA(s);
s=s.replace(‘e’, ‘a’);
System.out.println(s);
}
public static void methodA(String str){
str+=“World”;
}
}
上述代码的运行结果为: 32.1
。
答案:
32.1: Hallo
答案正确 -
已知代码:
class MyDate{
int year;
int month;
int day;
MyDate(int year,int month,int day){
this.year=year;
this.month=month;
this.day=day;
}
}
public class Main{
public static void main(String args[]){
MyDate md1=new MyDate(2009,2,10);
MyDate md2=new MyDate(2009,2,10);
if(md1md2)
System.out.println("md1md2");
else
System.out.println(“md1!=md2”);
if(md1.equals(md2))
System.out.println(“md1 is equla to md2”);
else
System.out.println(“md1 is not equal to md2”);
}
}
运行上述代码,写出其运行结果: 33.1 33.2
答案:
33.1: md1!=md2
33.2: md1 is not equal to md2
答案正确 -
一个类如果实现一个接口,那么它就需要实现接口中定义的全部( ),否则该类就必须定义成( )。 34.1 34.2
答案:
34.1: 方法
34.2: 抽象类
答案正确 -
在Java中,用户自定义异常类必须继承 35.1
类, 用户人工抛出自定义异常使用关键词 35.2
。
答案:
35.1: Exception
35.2: throw
答案正确 -
InputStreamReader类是用于将( )转换为( )。 36.1 36.2
答案:
36.1: 字节流
36.2: 字符流
答案正确 -
在java.io包内包含了处理各种流的基本类,所有的字节输出流都继承于 37.1
类,所有的字符输入流都继承于 37.2
类。
答案:
37.1: OutputStream
37.2: Reader
答案正确
共计37
进程已结束,退出代码为 0