编译器将显示第7行有错误
程序编译并打印true
程序编译并打印false
程序编译但在第7行引起了一个运行期意外
第1题:
A.public class test { public int x = 0; public test(int x) { this.x = x; } }
B.public class Test{ public int x=0; public Test(int x) { this.x = x; } }
C.public class Test extends T1, T2 { public int x = 0; public Test (int x) { this.x = x; } }
D.public class
第2题:
阅读以下说明和Java代码,回答问题1和问题2,将解答填写在对应栏内。
【Java代码】
class usethread implements (1) {
int num
usethread(int n){
num=n;
}
public void (2) {
for(int i=0;i<3;i++)
System.out.println("running:"+num);
System.out.println("finished:"+num);
}
public class multhread{
public static void main(String args[]) (3) InterruptedException{
Thread m1=new Thread(new usethread(1));
Thread m2=new Thread(new usethread(2));
m1.start();
m2.start();
m1.join();
m2.join();
}
}
【问题1】
补充完整上面Java代码中(n)处。
【问题2】
写出上面Java代码运行的结果。
第3题:
阅读以下说明和Java代码,请回答问题1和问题2。
【说明】
己知类Stock和类cxyjava都定义在cxyjava.java文件中,类Stock的定义中第14行前共有四行出现了错误,将下面代码修改正确并完善后的输出结果为:
0:0
1:23
【Java代码】
01 public class Stock{
02 static {
03 shares = 0;
04 share val = 0.0;
O5 }
06 public Stock(){getData();}
07 public Stock(int n, iht pr=0){
08 shares = n;
09 share val = pr;
10 getData();
11 }
12 public void getData() {
13 System.out.println(shares + ":"+share_val);
14 }
15 private int shares;
16 private int share_val;
17 };
18
19 public class cxyjava{
20 public static void main(String args[]) {
21 Stock a = (1) ;
22 Stock b = new Stock(1,23);
23 //其他无输出代码省略
24 }
25 }
请指出错误所在行号并给出该行修改后的完整结果。
第4题:
下列代码的输出结果是( )。
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 test
{
public static void main(String args[])
{
child myc=new child();
myc.printall();
}
}
A.import java.awt.*;
B.import java.applet.applet;
C.import java.io.*;
D.import java, awt.graphics;
第5题:
在下列源代码文件Test.java中, ( )是正确的类定义。
A.public class test{
B.public class Test{ public int x=0;public int x=0; public test (intx) public Test (int x){ {this.x=x; this.x=x;} }} }
C.public class Test extends T1,T2{
D.protected class Test extends T2{ public int=0;public int x=0; public Test(int x){Public Test (int x){ this.x=x;this.x=x: }} }}
第6题:
阅读以下说明和Java程序代码,将应填入(n)处的字句写在答题纸的对应栏内。
【说明】
在下面的Java程序代码中,类SalesTicket能够完成打印票据正文的功能,类 HeadDecorator与FootDecorator分别能够完成打印票据的台头和脚注的功能。
已知该程序运行后的输出结果如下所示,请填补该程序代码中的空缺。
这是票据的台头!
这是票据正文!
-------------------
这是票据的脚注!
这是票据的台头!
这是票据的脚注!
【tava程序代码】
public class SalesTicket {
public void printTicket() {
System. out. println ( "这是票据正文 ! ");
}
}
public class Decorator extends SalesTicket{
SalesTicket ticket;
public Decorator(SalesTicket t) {
ticket = t;
}
public void printTicket(){
if(ticket != null)
ticket.printTicket();
}
public class HeadDecorator extends Decorator{
public HeadDecorator(SalesTicket t) {
(1)
}
public void printTicket() {
System. out.println("这是票据的台头! ");
super.printTicket();
}
}
public class FootDecorator extends Decorator{
public FootDecorator(SalesTicket t) {
(2);
}
public void printTicket() {
super, printTicket ();
System. out.println ("这是票据的脚注!");
}
}
public class Main {
public static void main(String[] args) {
T = new HeadDecorator( (3));
T=(4);
System.out.println("------------------------------------");
T = new FootDecorator((5));
T.printTicket ();
}
}
第7题:
第8题:
给出下列java源代码: //Point x Public class Interesting{} 在源代码//point x处添加()能符合java语法
第9题:
给定如下Java程序片断: class A{ public A (){ System.out.println("A"); } } class B extends A{ public B(){ System.out.println("B"); } public static void main(String[] args){ B b=new B(); } } 上述程序将()。
第10题:
ClassOne.java: 1. package com.abe.pkg1; 2. public class ClassOne { 3. private char var = ‘a’; 4. char getVar() { return var; } 5. } ClassTest.java: 1. package com.abe.pkg2; 2. import com.abc.pkg1.ClassOne; 3. public class ClassTest extends ClassOne { 4. public static void main(String[] args) { 5. char a = new ClassOne().getVar();6. char b = new ClassTest().getVar(); 7. } 8. } What is the result?()
第11题:
MyExample
Aptech
Online
产生异常: java.lang.ArrayIndexOutOfBoundsException
第12题:
不能通过编译
通过编译,输出为:A B
通过编译,输出为:B
通过编译,输出为:A
第13题:
如下两个源程序文件,分别编译后,运行Example.class文件,运行结果为______。
AB.java文件代码如下;
package test;
public class AB
{
int a=60;
public void show()
{
System.out.println(”a=”+a);
}
Example.java文件代码如下:
import test.AB;
class Example
{
public static void main(String args[])
{
AB bj=new AB();
obj.show();
}
}
第14题:
下列哪个选项的java源文件代码片段是不正确的?
A.package testpackage; public class Test{ }
B.import java. io. *; package testpaekage; public class Test { }
C.import java.io.*; class Person { } public class Test { }
D.import java.io.*; import java. awt.*; public class Test{ }
第15题:
在下列源代码文件Test.java中,正确定义类的代码是( )。
A.pblic class test { public int x=0; public test(int x) { this. x=x;} }
B.public class Test { public int x=0; public Test(int x) { this. x=x;} }
C.public class Test extends T1,T2{ public int x = 0; public Test(int x){ this. x = x; } }
D.protected class Test extends T2{ public int x = 0; public Test(int x) { this. x = x; } }
第16题:
下列哪个选项的java源文件程序段是不正确的? ( )
A.package testpackage; public class Test{ }
B.import java.io.*; package testpackage; public class Test{ }
C.import java.i.*; class Person{} public class Test{ }
D.import java.io.*; import java.awt.*; public class Test { }
第17题:
编译和运行以下代码结果为:
1. public class EqualsTest{
2. public static void main(String args[]){
3. byte A=(byte)4096;
4. if(A== 4096、System.out.println("Equal");
5. else System.out.println("Not Equal");
6. }
7. }
A.在第3行出现转换丢失精度的编译错误.
B.输出 "Not Equal".
C.输出 "Equal".
第18题:
( 8 )在下列 Java applet 程序的横线处填入代码,使程序完整并能够正确运行。
Import java. awt. *;
Import java. applet. *;
Public class Greeting extends applet{
Public void 【 8 】 (Graphics g) {
g.drawSting( “ how are you! ” ,10,10);
}
}

第19题:
第20题:
在Java中,下列代码将输出()。 1. public class integerequals 2. { 3. public static void main (String args[]) 4. { 5. Integer a= new Integer(3); 6. Integer b= new Integer(3); 7. System.out.println(a==b); 8. } 9. }
第21题:
1. public interface A { 2. public void doSomething(String thing); 3. } 1. public class AImpl implements A { 2. public void doSomething(String msg) { } 3. } 1. public class B { 2. public A doit() { 3. // more code here 4. } 5. 6. public String execute() { 7. // more code here 8. } 9. } 1. public class C extends B { 2. public AImpl doit() { 3. // more code here 4. } 5. 6. public Object execute() { 7. // more code here 8. } 9. } Which statement is true about the classes and interfaces in the exhibit?()
第22题:
Compilation will fail.
Compilation succeeds and no exceptions are thrown.
Compilation succeeds but an exception is thrown at line 5 in ClassTest.java.
Compilation succeeds but an exception is thrown at line 6 in ClassTest.java.
第23题:
import java.awt.*
package local.util
class MoreInteresting{}
protected class MoreInteresting{}
第24题:
编译器将显示第7行有错误
程序编译并打印true
程序编译并打印false
程序编译但在第7行引起了一个运行期意外