下面程序是关于类的继承的用法。阅读下面程序,根据程序中的注释在每一条横线处填写一个语句,使程序的功能完整,且运行程序后的输出结果为:
I am parentclass!
I am childclass!
I am childclass!
注意: 请勿改动main()主方法和其他已有的语句内容,仅在下划线处填入适当的语句。
class Parent {
void printMe() {
System.out.println("I am parentclass!");
}
}
class Child extends Parent {
void printMe() {
System.out.println("I am childclass!");
}
void printAll() {
______________.printMe ( ); // 调用父类的方法
______________. printMe ( ); //调用本类的方法
printMe ( );
}
}
public class TestJieCheng {
public static void main(String args[]) {
______________
myC.printAll();
}
}
第1题:
下面的程序的功能是简单的进行键盘输入测试,请在程序的每条横线处填写一个语句,使程序的功能完整。
注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。
____________________
public class TestKeyBoardInPut
{public static void main(String[] args)
{String yourname=JOptionPane. ____________________ ("What is your name?");
System.out.println("Hello"+yourname);
____________________.exit(0);
}
}
第2题:
下面的程序是用do_while语句计算10的阶乘。请在程序的每条横线处填写一个语句,使程序的功能完整。
注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。
源程序文件代码清单如下:
public class DoWhileLoop
{
public static void main(________)
{
int n=10;
long result=1;
do
{
_______________
}
______________
System.out.println("10的阶乘为: "+result);
}
}
第3题:
在下面的程序的横线处填上适当的语句,使该程序的输出结果为12。
include<iostream>
using namespace std;
class TestClass
{
public:
int a,b;
TestClass(int i,int j)
{
a=i;
b=j;
}
};
class TestCla
第4题:
下面是一个Applet小程序,其功能为:以坐标(10,20)为起点,画一条长为80个像素点的绿色直线,请在横线处填写一条语句,使程序的完整。
注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。
______________________
import java.awt.*;
public class test_drawline extends Applet
{
public void paint(_______________)
{
g.setColor(Color.green);
_____________________
}
}
第5题:
下面是关于字符界面基本输入输出的程序,请在程序的每条横线处填写一个语句,使程序的功能完整。
注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。
______________________
public class SimpleCharInOut{
public static void main(String args[]){
char c=" ";
System.out.println("Enter a character please: ");
try{
____________________//接受用户键盘输入的字符并保存在变量c中
}
catch(________________________e){}
System.out.println("You've entered character "+c);
}
}