题目内容

读下面程序,写出程序运行结果。classPerson{inta,b;publicPerson(inta,intb){System.out.println("a,b:"+a+b);}}classStudentextendsPerson{intc;publicStudent(inta,intb,intc){super(a,b);this.c=c;System.out.println("c:"+c);}publicvoidshow(){System.out.println("a,b,c:"+a+b+c);}}publicclassclassDemo1{publicstaticvoidmain(String[]args){Personp1=newPerson(1,2);Studentp2=newStudent(2,3,4);p2.show();}}运行结果为:

查看答案
更多问题

读下面程序,写出程序运行结果。abstractclassGraph{inta;publicGraph(){a=1;}publicGraph(inta){this.a=a;}publicabstractvoidshowArea();}classRectextendsGraph{intb;publicRect(inta,intb){super(a);this.b=b;}publicvoidshowArea(){System.out.println("Area:"+(a*b));}}classCircleextendsGraph{publicCircle(){};publicCircle(inta){super(a);}publicvoidshowArea(){System.out.println("Area:"+(3.14*a*a));}}publicclassclassDemo1{publicstaticvoidmain(String[]args){Graphg1;g1=newRect(2,3);g1.showArea();g1=newCircle(2);g1.showArea();g1=newCircle();g1.showArea();}}运行结果为:

在(1)~(3)处填上适当的语句,使程序能正常运行。.abstractclassPerson{public(1)show();}classStudentextendsPerson{public(2){System.out.println("Student");}}(3){publicvoidshow(){System.out.println("Teacher");}}publicclassDemo{publicstaticvoidmain(String[]args){Personp;p=newStudent();p.show();p=newTeacher();p.show();}}

按要求编写一个Java应用程序:(1)定义一个接口CanCry,描述会吼叫的方法publicvoidcry()。(2)分别定义狗类(Dog)和猫类(Cat),实现CanCry接口。实现方法的功能分别为:打印输出“我是狗,我的叫声是汪汪汪”、“我是猫,我的叫声是喵喵喵”。(3)定义一个主类G,①定义一个voidmakeCry(CanCryc)方法,其中让会吼叫的事物吼叫。②在main方法中创建狗类对象(dog)、猫类对象(cat)、G类对象(g),用g调用makecry方法,让狗和猫吼叫。

定义一个接口,接口中有3个抽象方法如下。(1)“longfact(intm);”方法的功能为求参数的阶乘。(2)“longintPower(intm,intn);”方法的功能为求参数m的n次方。(3)“booleanfindFactor(intm,intn);”方法的功能为判断参数m加上参数n的和是否大于100。定义类实现该接口,编写应用程序,调用接口中的3个方法,并将调用方法所得的结果输出。

答案查题题库