}
}
cUnit = unit;
public void printCourseInfo() { }
System.out.println(\课程号:\课程名:\学分:\
+ cUnit);
class CourseTest { }
6、以下程序的输出结果为__汤姆猫体重:20.0斤___________________。 public class Tom {
public static void main(String[] args) {
Tom.name = \汤姆猫\Tom cat = new Tom(); cat.setWeight(20); private void out() { }
System.out.println(name + \体重:\斤\public void setWeight(float weight) { }
this.weight = weight; private float weight; private static String name;
public static void main(String[] args) { }
Course c;
c = new Course(\c.printCourseInfo();
}
}
cat.out();
7、以下程序的输出结果_姓名:Tom 年龄:15 家庭住址:金水区 电话:_66123456 学校:九中_______________。 public class Father { }
class Son extends Father {
void out() {
public Son(String name, int age) { }
super(name, age); String school; void outOther() { }
System.out.print(\家庭住址:\System.out.print(\电话:\void out() { }
System.out.print(\姓名:\System.out.print(\年龄:\public Father(String name, int age) { }
this.name = name; this.age = age; String name, address, tel; int age;
}
}
super.out(); super.outOther();
System.out.println(\学校:\
public static void main(String args[]) { }
Son son = new Son(\son.address = \金水区\son.school = \九中\son.tel = \son.out();
8、下列程序的运行结果是____1 23 4 5_________________。 public class MyClass { }
public static void main(String[] args) { }
MyClass my = new MyClass(); my.out(); void out() { }
for (int j = 0; j < a.length; j++)
System.out.print(a[j] + \
int a[] = { 1, 2, 3, 4, 5 };
五、程序填空题
1.public class Sum{
public static void main(String [] args){
int j=10;
System.out.println(\
}
}
calculate(j);
System.out.println(\
static void calculate (int j){ }
for (int i = 0;i<10;i++)
j++;
System.out.println(\
输出结果为:
j is : (1) 10 j in calculate() is : (2) 20 At last j is : (3) 10
2. 按要求填空
abstract class SuperAbstract{ }
interface AsSuper { }
abstract class SubAbstract extends SuperAbstract implements AsSuper {
public void b(){…} }
public class InheritAbstract extends SubAbstract{
public void x(){…} public int c(int i ) {…} public String f(){…}
public static void main(String args[]){ abstract String f(); void x(); void a(){…} abstract void b(); abstract int c(int i);
}
}
InheritAbstract instance=new InheritAbstract(); instance.x(); instance.a(); instance.b(); instance.c(100);
System.out.println(instance.f());
在以上这段程序中:
抽象类有:SuperAbstract和 (1) (写出类名)SuperAbstract (3) (写出接口名)AsSuper
AsSuper中的x()方法是 抽象 (4) 方法,所以在InheritAbstract中必须对它进行 覆盖和实现 (5)
3. 按注释完成程序 public class Leaf { }
输出结果为 i = 3 (3)
private int i = 0; //此属性值用于检验
Leaf increment(){ //定义方法increment(),返回值是Leaf类的对象 }
void print() { }
public static void main(String args[]){
Leaf x = new Leaf() (2) ; //创建Leaf类的对象x x.increment().increment().increment().print(); System.out.println(\
i++;
return this (1) ;//将当前对象的地址作为返回值返回
非抽象类有: (2) (写出类名)InheritAbstract接口有:
}//多次调用方法increment(),返回的都是x的地址,i 值表示调用次数
五、程序阅读题