浙江财经大学东方学院课程期末考试试卷
public void printCourseInfo() {
System.out.println(\课程号:\ + cNumber + \课程名:\ + cName + \学
分:\ + cUnit); } }
class CourseTest { }
public static void main(String[] args) { }
Course c;
c = new Course(\, \, 3); c.printCourseInfo();
3、以下程序的输出结果为__汤姆猫体重:20.0斤___。
public class Tom { }
public static void main(String[] args) { }
Tom.name = \汤姆猫\; Tom cat = new Tom(); cat.setWeight(20); cat.out(); private void out() {
System.out.println(name + \体重:\ + weight + \斤\); }
public void setWeight(float weight) { }
this.weight = weight; private float weight; private static String name;
4、以下程序的输出结果_姓名:Tom 年龄:15 家庭住址:金水区 电话:66123456 学校:九中_。
public class Father {
public Father(String name, int age) { String name, address, tel; int age;
第11页,共21页
浙江财经大学东方学院课程期末考试试卷
}
}
this.name = name; this.age = age;
void out() {
System.out.print(\姓名:\ + name); System.out.print(\年龄:\ + age); }
void outOther() {
System.out.print(\家庭住址:\ + address); System.out.print(\电话:\ + tel); }
class Son extends Father { }
public static void main(String args[]) { }
Son son = new Son(\, 15); son.address = \金水区\; son.school = \九中\; son.tel = \; son.out(); void out() {
super.out(); super.outOther();
public Son(String name, int age) { }
super(name, age); String school;
System.out.println(\学校:\ + school); }
5、下列程序的运行结果是__12345____。
public class MyClass {
void out() {
for (int j = 0; j < a.length; j++)
System.out.print(a[j] + \);
第12页,共21页
int a[] = { 1, 2, 3, 4, 5 };
浙江财经大学东方学院课程期末考试试卷
}
}
public static void main(String[] args) { }
MyClass my = new MyClass(); my.out();
1、 import java.io.*;
public class abc {
public static void main(String args [ ]) {
AB s = new AB(\VA.\
System.out.println(s.toString( )); } } class AB { String s1; String s2;
public AB(String str1, String str2) {
s1 = str1; s2 = str2; }
public String toString( ) {
return s1+s2; } }
运行结果:Hello! I love JAVA.
2、 import java.io.* ; public class abc {
public static void main(String args[ ])
第13页,共21页
浙江财经大学东方学院课程期末考试试卷
{ int i, s = 0 ;
int a[ ] = { 10 , 20 , 30 , 40 , 50 , 60 , 70 , 80 , 90 }; for ( i = 0 ; i < a.length ; i ++ ) if ( a[i]%3 = = 0 ) s += a[i] ; System.out.println(\ } }
运行结果:s = 180
3、import java.io.* ; public class abc {
public static void main(String args[ ]) {
System.out.println(\ }
}
class SubClass extends SuperClass { int c;
SubClass(int aa, int bb, int cc) {
super(aa, bb);
c=cc; } }
class SubSubClass extends SubClass { int a;
SubSubClass(int aa, int bb, int cc) { super(aa, bb, cc); A = aa+bb+cc; } void show() {
System.out.println(\
第14页,共21页
浙江财经大学东方学院课程期末考试试卷
}
}
运行结果:a=60 b=20
c=30
public class TestException {
public void CreateException() throws Exception{ throw new Exception(\ } public static void main(String[] args) { TestException te = new TestException(); try{
System.out.println(\ te.CreateException();
System.out.println(\ } catch(Exception ex){
System.out.println(\
System.out.println( ex.getMessage()); }
finally{ System.out.println(\ System.out.print(\ }} 输出:
try called start catch called new exception finally called main() finished
3.阅读程序后,写出程序运行结果。 class B extends A{ public B( ) {
System.out.println(\ } public void change(String s){ s = \ } } public class A {
public A( ){ System.out.println(\ public static void main(String[] args) { B b = new B( );
String s = %unchanged\ b.change(s);
System.out.println(\ }}
第15页,共21页
} }