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
ng toString()
notify()
notifyAll()
wait()
11、給出下面代碼:C
public class Person{
static int arr[] = new int[10];
public static void main(String a[])
{
tln(arr[1]);
}
}
下列説法中正確的是?
A.編譯時將產生錯誤;
B.編譯時正確,運行時將產生錯誤;
C. 輸出零;
D. 輸出空。
12、字符串是Java已定義的類型,關於它的構造函數,下面説法不正確的是: B
ng(char[] value, int offset, int count)
ng(int[] codePoints,int offset, int count)
ng(String original)
ng(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
sient
hronized
alize
ic
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類可以有多個父類。
小程序Applet的主類的父類必須是類Applet。
k語句可以用在循環和switch語句中。
6.在Java中,異常Exception是指程序在編譯和運行進出現的錯誤。
7.可以用new來創建一個類的實例,即對象。
使用16位的Unicode字符集,而不僅僅為ASCII字符集,因此Java字符是一個16位的無符號整數。
10.子類的成員變量能與其父類的`成員變量同名。
類中不能存在同名的兩個成員函數。
語言是編譯性語言。
l方法不能被覆蓋。
20.多數I/O方法在遇到錯誤是會拋出異常,因此在調用這些方法時必須對異常進行處理。
ract 是抽象修飾符,可以用來修飾類及其屬性和方法。
4.一個Java Applet源程序的主類能有多個父類。
6.用javac編譯Java源文件後得到代碼叫字節碼。
7.可以用類名調用實例方法。
9.要想在類中實現多線程,類必須繼承Thread類。
語言是平台無關的語言。
12.在類的靜態方法中可以訪問該類的非靜態數據成員。
中方法調用時參數傳遞都是按值傳遞的,因此從方法退出時,參數的值不會改變。
14.聲明為final的方法不能在子類中重載。
15.在子類中可以覆蓋一個private方法。
19.在方法定義中,所有可能發生的異常都必須用try{}catch(){}捕捉並處理
1.請寫出輸出結果
class change{
void changeint(int x){
x++;
} public static void main(String args[]){
int a=2;
tln("Before changed: "+"a="+a); //請系統輸出Before changed: a=
change cxz=new change();
geint(a);
tln("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 .*;
public class StrCompare
{
public static void main(String[] args)
{
String
str1 = "Hello, Java!",
str2 = "hello, java!";
tln(areToIgnoreCase(str2));
tln(ls(str2)); tln(lsIgnoreCase(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;
tln(
"j+and"+i);
j--;
}
i--;
}
}
}
答:
j+and3
j+and3
j+and2
j+and2
j+and1
j+and1
5、 import .*;
public class abc
{ public static void main(String args[ ])
{ AB s = new AB("Hello!","I love JAVA.");
tln(ring( ));
}
}
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;
tln(a.x);withstaticdata b=new withstaticdata();
b.x=2;
tln(b.x); tln(a.x); withstaticdata c=new withstaticdata();
tln(
"c.x="+c.x); }
}
答:2
public class StaticFun {
static void incr(){
withstaticdata.x++
;
}
public static void main( String [] args )
{
();
}
}
1、在橫線上填上適當的內容
import .*;
import et.*;
public class AppletLife extends Applet //聲明為Apple類
{
Color r;
public AppletLife() //初始化
{
tln("Applet initing...");
r = ;
}
public void start()
{
tln("Applet starting...");
}
public void stop()
{
tln("Applet stopping...");
}
public void paint(Graphics g)
{
tln("Applet painting...");
olor(r);
String("Painting here!", 50, 60 );
}
public void destroy()
{
tln("Applet destroy...");
}
}
2. 閲讀以下程序,請寫出輸出結果
public class tt {
public static void main(String[] args) {
String s=new String("Bicycle");
int iBegin=1;
int iEnd=3;
tln(tring(iBegin,i
End));}
}
答:ic
3、請在相應的劃線上填上代碼
public class CircumferenceTester {
public static void main(String args[]) {
Circle c1 = new Circle();
us = 50;
Circle c2 = new Circle();
us = 10;
double circum1 = umference();
double circum2 = umference();
tln(
"Circle 1 has circumference " + circum1);
tln(
"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 < h) && (2 * radius < ht);
}
}
4、閲讀以下程序,請寫出輸出結果
class father{
void speak(){
tln(
"I am father!");
}
}
public class son extends father{
void speak(){
k();
tln(
"I am son!");
}
public static void main(String args[]){
son cxz=new son();
k();
}}
答:
I am father!
I am son!
5.寫出下面程序的運行結果
import .*;
class Parent
{
void printMe()
{
tln("parent");
}
}
class Child extends Parent
{
void printMe()
{
tln("child");
}
void printAll()
{
tMe();
tMe();
printMe();
}
}
public class Class1
{
public static void main(String args[ ])
{
Child myC = new Child( );
tAll( );
}
}
答:
parent
child
child
6.寫出下面程序的運行結果
import .*;
public class abc
{
public static void main(String args[])
{
String s1 = "Hello!";
String s2 = new String("World!");
tln(at(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
tln("
半徑 面積 周長
");
t(());
t(" ");
t(());t(" ");
t(lelength());
}
}定義能
計算三角形的面積、周長的類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 (s * (s - a) * (s - b) * (s - c));
}
public double sjlength() {
return a + b + c;
}
public double s() {
return ngth() / 2;
}
}
import malFormat;
public class jxcomputer {
public static void main(String[] arg) {
js j = new js(3, 6, 8);
tln("a b c
面積 周長
");
t(());
t(" ");
t(());
t(" ");
t(());
t(" ");
DecimalFormat df = new DecimalFormat("#.00"); //
保留兩位小數,此句可以不用
t(at(()));
t(" ");
t(ngth());
}
}