问答题

下面程序是关于类的继承的用法。阅读下面程序,根据程序中的注释在每一条横线处填写一个语句,使程序的功能完整,且运行程序后的输出结果为: 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(); } }

【参考答案】

superthisChild myC=new Child();[解析] 本题主要考查super,this关键字以及如何生......

(↓↓↓ 点击下方‘点击查看答案’看完整答案 ↓↓↓)
热门 试题

问答题
下面是一个Applet程序,其功能是输入3个双精度浮点数:a,b,c,构成一个一元二次方程,a*x*x+b*x+c=0,其判别式d=b*b-4*a*c,若d为负数则输出“没有实根”,否则打印出2个实根。要求,有3个输入框,输入a,b,c,一个按钮,点击实现求根过程,一个不可编辑的文本区,用作输出结果。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。注意:不改动程序的结构,不得增行或删行。import java. io. *import java. awt. *import java. awt. event. *import java. applet. Applet; *<applet code= ex3_1. class width=800 height=400>< applet>* public class ex3_1 extends Applet implements ActionListener{Panel pane= new Panel();Label 11=new Label( a: )TextField tf1 =new TextField(5)Label 12 = new Label ( b: )TextField tf2=new TextField(5);Label 13=new Label( c: )TextField tf3=new TextField(5);Button btn= new Button( OK )Label 14=new Label( 答案 )TextField tf4=new TextField(20);ex3_1 obj3_1public void init(){pane. setLayout( new FlowLayout (FlowLayout. LEFT, 10,5 ) )pane. add(11)pane. add(tf1)pane. add(12)pane. add(tf2)add( North , pane)Panel p2=new Panel();p2. setLayout ( new FlowLayout ( FlowLayout. LEFT, 10, 5) )p2. add(13);p2. add(tf3)p2. add(btn)btn. addActionListener(this);add( Center ,p2)Panel p3=new Panel ()p3. setLayout ( new FlowLayout (FlowLayout. LEFT, 10,5 ) )p3. add(14)tf4. setEditable(false)p3. add(tf4)add( South ,p3)obj3_1 = new ex3_1 ( )}public void doReal(double a1,double a2,double a3,TextField tf)double d, x1, x2d=a1 * a1-4.0 * a2 * a3;if(d>=0.0)x1=(-a2+Math. sqrt(d)) (2.0 * a1);x2=(-a2+Math. sqrt(d)) (2.0 * a1);tr. setText( 2个实根:x1= +x1+ nx2= +x2);}else {tr. setText ( 没有实根! )}}public void actionPerformed(ActionEvent ae)double a, b, c;try{a= new Double(tf1. getText( ) ). doubleValue( );b= new Double(tf2. getText( ) ). doubleValue( );c= new Double(tf3. getText( ) ). doubleValue( );obj3_1, doReal(a,b,c, 14);} catch(NumberFormatException nfe) {tf4. setText( wrong number! )}}}ex3_l. html<HTML><HEAD><TITLE> ex3_l < TITLE>< HEAD><BODY><applet code= ex3_l, class width=800 height=400>< applet>< BODY>< HTML>