27.程序填空:
public void getData() {
String str = JoptionPane.showInputDialog(null,”Input:”);
if (str.equals(“”){
throw new IOException();
}
)
28.对象称为类的 。
29.Java程序的源文件以 为扩展名,编译后的文件以 为扩展名。
二、简答题:
1.类和对象的概念和关系是什么?
2.请说明对象声明和对象生成之间的区别,并使用内存状态图举例说明这种区别。
3.this和super两个保留字的意义和作用是?
4.构造器方法有什么特点和作用?
5.保留字throw和throws有什么区别?
6.将下面的while 循环改写为for循环
int count =1, sum = 0;
while ( count <= 30 ) {
sum += count;
count +=3;
}
7.Java语言编译和执行的过程是?
8.检查型异常和非检查型异常有何区别?
9.请改造下面的构造方法,使第一个构造方法调用第二个构造方法。
public ClassOne(int alpha) {
this.alpha = alpha;
this.beta = 0;
}
public ClassOne(int alpha , int beta) {
this.alpha = alpha;
this.beta = beta;
}
10.Java有哪几个访问权限修饰符,各起到什么作用?
11.请说明实例方法、类方法和构造器方法的特点和区别stylus。
三、请写出下面的代码段的输出结果:
1.class Q2main{
electric是什么意思 public static void main(string[] args) {
QuestionTwo q2;
q2= new QuestionTwo();
q2.init();
q2.increment();
q2.increment();
system.out.Count());
}
}
class QuestionTwo{
private int count;
public void int(){
count=1;
}
public void increment(){
count=count+1;
}
public int getCount(){
return count;
}
}
2.int gradeLevel;
switch (gradeLevel) {
ca 1:
System.out.print("Go to the 101");
ca 2:
System.out.print("Go to 202");
break;
ca 3:
System.out.print("Go to 303");
ca 4:
System.out.print("Go to 404");
break;
default:
System.out.print("default");
}
如果变量gradeLevel 在switch语句之前为以下数值,上述程序代码段执行后,将分别输出什么?
a) 2
b) 3
c) coven4政府英文
d) 5
3.int x;
for (int width = 1; width <=20, width++){imax什么意思
for (int length = 5, length <=25, length+=5){
x = width * length;
System.out.print (" " + x);
}
System.out.println("");
}
输出结果为:
4.class MyException1 extends Exception {
public MyException1() {}
public MyException1(String msg) { super(msg); }
}
public class ExceptionTest{
public static void f() throws MyException1 {
System.out.println("The 1st line of f()");
throw new MyException1("Exception1:Originated in f()");
}
public static void main(String[] args) {
System.out.println("The 1st line of main()");
try {
System.out.println("The 2nd line of main()");
f();
System.out.println("The 3rd line of main()");
}catch(MyException1 e) {
System.out.Message());
}
finally {
System.out.println("The 4th line of main()");
}
System.out.println("The 5th line of main()");
}
}
输出结果为:
5.import java.io.*;
class Ba{
Ba(){
System.out.println("Ba()");
}
void m1(){
System.out.println("Ba.m1()");
}
}
class Derived extends Ba{
Derived(){
this("default");
System.out.println("Derived()");
}
Derived(String ss){
System.out.println(ss);
}
void m1(){
System.out.println("Derived.m1()");
}
}
public class Application1{
public static void main(String args[]) {