JAVA
选择题
1、下列哪个类声明是正确的?D
A)abstract final class HI{•••} B)abstract private move(){•••}
C)protected private number; D)public abstract class Car{•••}
2、给出下面代码:
public class Person{ static int arr[] = new int[10]; public static void main(String a[]) { System.out.println(arr[1]); } } 下列说法中正确的是? C A.编译时将产生错误; B.编译时正确,运行时将产生错误; C. 输出零; D. 输出空。
3、字符串是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)
4、下列说法中正确的是: C A.导入包会影响程序的性能 B.包存储在类库中 C.包是类的容器D.上述说法都不对 5、下列不是String类的常用方法是:C A、boolean equals(String str) B、int compareTo(String str) C、int SetindexOf(String str) D、int lastIndexOf(String str) 6、表达式:(x>y) ? (z>w) ?x:z:w,(其中x=5,y=9,z=1,w=9)的值为:D
A、5 B、8
C、1 D、9
7、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[] )
8、欲构造ArrayList类的一个实例,下列哪个方法是正确的 ? B
A. ArrayList myList=new Object();
B. ArrayList myList=new ArrayList();
C. myList= new Object();
D. myList= new ArrayList();
9、下列叙述中,错误的是: D
A、父类不能替代子类
B、子类能够替代父类
C、子类继承父类
D、父类包含子类
10、Java应用程序中,程序执行的总入口方法是:B
A、start() B、main() C、run() D、init()
判断题
1.一个Java类可以有多个父类。错
2.break语句可以用在循环和switch语句中。对
3.在Java中,异常Exception是指程序在编译和运行进出现的错误。对 订正:错
4.可以用new来创建一个类的实例,即对象。对
5.子类的成员变量能与其父类的成员变量同名。对
6.Java类中不能存在同名的两个成员函数。错
7.Java语言是编译性语言。对
8.final方法不能被覆盖。对
9.abstract 是抽象修饰符,可以用来修饰类及其属性和方法。对
10.用javac编译Java源文件后得到代码叫字节码。对
11.可以用类名调用实例方法。对 订正:错
12.在类的静态方法中可以访问该类的非静态数据成员。对 订正:错
13.Java中方法调用时参数传递都是按值传递的,因此从方法退出时,参数的值不会改变。错 订正:对
14.声明为final的方法不能在子类中重载。对 订正:错
15.在子类中可以覆盖一个private方法。错
16.在方法定义中,所有可能发生的异常都必须用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);
change cxz=new change();
cxz.changeint(a);
System.out.println("After changed: "+"a="+a);
}
}
输出结果为: Before changed: a= 2 After changed: a=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);3and3 3and2 3and1 j--;2 2 2 } i--;2 1 0 } } } 输出结果: 3and3 2and3 订正:3and3
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 str1hello , String str2i love java ) { s1 = str1; s2 = str2; } public String toString( ) { return s1+s2;} } 输出结果: Hello I love JAVA 2
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); } } 输出结果: c.x= 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,iEnd));}
} 输出结果: ic
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