设有程序如下: public class jzh0319 { public static void main(String args[]) { subClass sc=new subClass(); } } class superClass { superClass() { System.out.println("父类");} } class subClass extends superClass { subClass() {System.out.println("子类"); } } 其输出结果的第二行为:子类。()此题为判断题(对,错)。
设有程序如下: public class jzh0319 { public static void main(String args[]) { subClass sc=new subClass(); } } class superClass { superClass() { System.out.println("父类");} } class subClass extends superClass { subClass() {System.out.println("子类"); } } 其输出结果的第二行为:子类。()
此题为判断题(对,错)。
相关考题:
已知类SubClass的getSum方法返回其父类成员i与类SubClass成员i的和,类SuperClass中的getSum为纯虚拟函数,程序中的第23行有错误,请修改该错误并给出修改后的完整结果,然后完善程序中的空缺,分析程序运行到第15行且尚未执行第15行的语句时成员变量j的值,最后给出程序运行后的输出结果。[C++代码]01 inclUde<iostream>02 using namespace std;03 class SuperClass {04 private:05 int i;06 publiC:07 SuperClass()(i=5;)08 virtual iht getValueO(return i ;)09 virtual int getSum()=0;10 };11 class SubClass:public SuperClass{12 int J ;13 public:14 SubClass(int j):j(0){15 (1) =j; //用参数j的值更新数据成员16 };17 int getValue(){return j;)18 int getSum(){19 return (2) getValue()+j;20 }21 };22 void main(void){23 SuperClass s=new SubClass(-3);24 cout<<s->getValue()<<"";25 tout<<s->getSum()<<endl;26 delete s;27 }
下列哪个类声明是正确的?A.abstract class G2 extends superClassl,superClass2{……}B.abstract public class classmates{……}C.public final class NewClass extends superClass implements Interfacel{……}D.public abstract class String{……}
下面程序的输出结果是什么? class C1{ static int j=0; public void method(int a){ j++; } } class Test extends C1{ public int method(){ return j++; } public void result(){ method(j); System.out.println(j+method()); } public static void main(String args[]){ new TeA.0B.1C.2D.3
执行下列代码后,输出的结果为( )。 class Base { int x = 30; void setX( ) {x=1O;} } class SubClass extends Base { int x=40; void setX ( ) {x=20;} int getX( ) {return super. x; } } public class Test { public static void main(String[ ] args) { SubClass sub=new SubClass( ); sub. setX( ); System. out. println(sub, getX( ) ); } }A.10B.20C.30D.40
interface A{int x = 0;}class B{int x =1;}class C extends B implements A {public void pX(){System.out.println(x);}public static void main(String[] args) {new C().pX();}}
下面程序输出的结果是什么? ( ) public class Quiz2 { public static void main(String args[]) { try {throw new MyException(); }catch(Exception e) { System.out.println("It's caught!"); }finally{ System.out.println("It's finally caught!"); } } } class MyException extends Exception{}A.It's finally caught!B.It's caught!C.It's caught!/It's finally caught!D.无输出
使下列程序正常运行并且输出“Hello!”,横线处应填写的内容是( )。 class Test { public static void main(string[]args){ Test t=new Test; start; } Public void run{ System.out.println("Hello!¨); )A.extends ThreadB.extends FloatC.extends IostreamD.extends Stdio
已知类SubClass的getSum方法返回其父类成员i与类SubClass成员j的和;类SuperClass中的getSum为抽象函数,程序中的第14行有错误,请修改该错误并给出修改后的完整结果,然后完善程序中的空缺,当程序运行到第22行且尚未执行第22行语句时成员变量i的值,最后给出程序运行后的输出结果。[Java代码]行号 代码01 public class UainJava{02 public static void main(String[]args){03 SuperClass s=new SubClass();04 System.out.printin(s.getValue());05 System.out.printIn(s.getSum()):06 }07 }08 abstract class SuperClass {09 private int i;10 public SuperClass(){i=5;}11 public int getValue(){12 return i:13 }14 public final abstract int getSum():15 }16 class SubClass extends SuperClass{17 int j;18 public SubClass(){19 this(-3);20 }21 public SubClass(int j){22 (1) .j=j;23 }24 publiC int getValue()(return j;}25 public int getSum(){26 return (2) .getValue()+j;27 }28
下列哪个类声明是正确的? ( )A.abstract class G2 extends superClass1,superClass2{...}B.abstract public class classmates{...}C.public final class NewClass extends superClass implemnets Interface1{...}D.public abstract class String{...}
下列哪个类声明是正确的? ( )A.abstract class G2 extends superClass1, superClass2 {…}B.abstract public class classmates{…}C.public final class NewClass extends superClass implemnets Interfacel{…}D.public abstract class String{…}
考虑如下代码:class Tree{}class Pine extends Tree{}class Oak extends Tree{}public class Forest {public static void main( String[] args ) {Tree tree = new Pine();if( tree instanceof Pine )System.out.println( "Pine" );if( tree instanceof Tree )System.out.println( "Tree" );if( tree instanceof Oak )System.out.println( "Oak" );elseSystem.out.println( "Oops" );}}则输出结果中有哪些?A.Pine B.Tree C.Forest D.Oops E.无输出
设有程序如下: public class jzh0319 { public static void main(String args[]) { subClass sc=new subClass(); } } class superClass { superClass() { System.out.println("父类");} } class subClass extends superClass { subClass() {System.out.println("子类"); } } 其输出结果只有一行。()此题为判断题(对,错)。
设有程序如下: public class jzh0319 { public static void main(String args[]) { subClass sc=new subClass(); } } class superClass { superClass() { System.out.println("父类");} } class subClass extends superClass { subClass() {System.out.println("子类"); } } 其输出结果的第一行是子类。()此题为判断题(对,错)。
设有程序如下: public class jzh0319 { public static void main(String args[]) { subClass sc=new subClass(); } } class superClass { superClass() { System.out.println("父类");} } class subClass extends superClass { subClass() {System.out.println("子类"); } } 其输出结果的第一行是:父类。()此题为判断题(对,错)。
设有程序如下: abstract class absclass { abstract void method1(); } class conclass extends absclass { public void method1() { System.out.println("子类");} } public class mainclass { public static void main(String args[]) { absclass ac1=new absclass(); //语句1 absclass ac2=new conclass(); //语句2 ac2.method1(); //语句3 } } 则main()方法中的第一条语句(即语句1)可以顺利通过编译。()此题为判断题(对,错)。
给定如下Java程序片断: class A{ public A (){ System.out.println("A"); } } class B extends A{ public B(){ System.out.println("B"); } public static void main(String[] args){ B b=new B(); } } 上述程序将()。 A、不能通过编译B、通过编译,输出为:A BC、通过编译,输出为:BD、通过编译,输出为:A
class MyThread extends Thread { public void run() { System.out.println(“AAA”); } public void run(Runnable r) { System.out.println(“BBB”); } public static void main(String[] args) { new Thread(new MyThread()).start(); } } What is the result?() A、 AAAB、 BBBC、 Compilation fails.D、 The code runs with no output.
class A { public A() { System.out.println(“hello from a”); } } class B extends A { public B () { System.out.println(“hello from b”); super(); } } public class Test { public static void main(String args[]) { A a = new B(); } } What is the result when main is executed?() A、 Compilation fails.B、 hello from aC、 hello from bD、 hello from b hello from aE、 hello from a hello from b
class Super { public int i = 0; public Super(String text) { i = 1; } } public class Sub extends Super { public Sub(String text) { i = 2; } public static void main(String args[]) { Sub sub = new Sub(“Hello”); System.out.println(sub.i); } } What is the result?() A、 0B、 1C、 2D、 Compilation fails.
1. class SuperClass { 2. public a geta() { 3. return new a(); 4. } 5. } 6. class SubClass extends SuperClass { 7. public b geta() { 8. return new b(); 9. } 10. } Which is true?() A、 Compilation will succeed if a extends b.B、 Compilation will succeed if b extends a.C、 Compilation will always fail because of an error in line 7.D、 Compilation will always fail because of an error in line 8.
class TestA { public void start() { System.out.println(”TestA”); } } public class TestB extends TestA { public void start() { System.out.println(”TestB”); } public static void main(String[] args) { ((TestA)new TestB()).start(); } } What is the result?() A、 TestAB、 TestBC、 Compilation fails.D、 An exception is thrown at runtime.
现有: class TestA { public void start() { System.out.println("TestA"); } } public class TestB extends TestA { public void start() { System.out.println("TestB"); } public static void main (string[] args) ( ((TestA)new TestB()).start(); ) } 运行结果是哪项?() A、 TeStAB、 TeStBC、编译失败D、运行时抛出异常
Which three statements are true?()A、A final method in class X can be abstract if and only if X is abstract.B、A protected method in class X can be overridden by any subclass of X.C、A private static method can be called only within other static methods in class X.D、A non-static public final method in class X can be overridden in any subclass of X.E、A public static method in class X can be called by a subclass of X without explicitly referencing the class X.F、A method with the same signature as a private final method in class X can be implemented in a subclass of X.G、A protected method in class X can be overridden by a subclass of X only if the subclass is in the same package as X.
单选题1. class SuperClass { 2. public a geta() { 3. return new a(); 4. } 5. } 6. class SubClass extends SuperClass { 7. public b geta() { 8. return new b(); 9. } 10. } Which is true?()A Compilation will succeed if a extends b.B Compilation will succeed if b extends a.C Compilation will always fail because of an error in line 7.D Compilation will always fail because of an error in line 8.
单选题class TestA { public void start() { System.out.println(”TestA”); } } public class TestB extends TestA { public void start() { System.out.println(”TestB”); } public static void main(String[] args) { ((TestA)new TestB()).start(); } } What is the result?()A TestAB TestBC Compilation fails.D An exception is thrown at runtime.
单选题现有: class TestA { public void start() { System.out.println("TestA"); } } public class TestB extends TestA { public void start() { System.out.println("TestB"); } public static void main (string[] args) ( ((TestA)new TestB()).start(); ) } 运行结果是哪项?()A TeStAB TeStBC编译失败D运行时抛出异常
单选题给定如下Java程序片断: class A{ public A (){ System.out.println("A"); } } class B extends A{ public B(){ System.out.println("B"); } public static void main(String[] args){ B b=new B(); } } 上述程序将()。A不能通过编译B通过编译,输出为:A BC通过编译,输出为:BD通过编译,输出为:A