编程题:Class father{fathe() {}Class sun extends father{ son() {…..}Public static void main(){ son a=new father();}}此程序是否正确,为什么?

题目

编程题:

Class father{fathe() {}

Class sun extends father

{ son() {…..}

Public static void main()

{ son a=new father();

}

}

此程序是否正确,为什么?


相似考题
更多“编程题:Class father{fathe() {}Class sun extends father{ son() {…..}Public static void main(){ son a=new father();}}此程序是否正确,为什么?”相关问题
  • 第1题:

    有如下程序: include using namespace std; class PARENT { public: PARENT() { cout

    有如下程序:

    include <iostream>

    using namespace std;

    class PARENT

    {

    public:

    PARENT() { cout <<"PARENT"; }

    };

    class SON : public PARENT

    {

    public:

    SON() {cout << "SON"; }

    };

    int main()

    {

    SON son;

    PARENT *p;

    p = &son;

    return 0;

    }

    执行上面程序的输出是______。


    正确答案:PARENTSON
    PARENTSON 解析:此题考查的是派生类的构造。主函数开始在定义SON类的对象son时,会先执行PARENT类的构造函数再执行SON类的构造函数,输出 “PAKENTSON”;接下来的语句定义PARENT和让指针p指向son对象,都并未创建任何对象,所以不会调用构造函数。故最终的输出结果是:PARENTSON。

  • 第2题:

    使下列程序正常运行并且输出“Hello!”,横线处应填写的内容是( )。 class Test { public static void main(string[]args){ Test t=new Test; start; } Public void run{ System.out.println("Hello!¨); )

    A.extends Thread

    B.extends Float

    C.extends Iostream

    D.extends Stdio


    正确答案:A
    A。【解析】从后面重写了run方法来看,这是通过继承Thread类,并重写run方法定义线程体,然后创建该子类的对象的方式来创建线程。

  • 第3题:

    写出程序的输出结果

    public abstract class A

    {

    public A()

    {

    Console.WriteLine('A');

    }

    public virtual void Fun()

    {

    Console.WriteLine("A.Fun()");

    }

    }

    public class B: A

    {

    public B()

    {

    Console.WriteLine('B');

    }

    public new void Fun()

    {

    Console.WriteLine("B.Fun()");

    }

    public static void Main()

    {

    A a = new B();

    a.Fun();

    }

    }


    正确答案:
     

  • 第4题:

    阅读下面程序 public class Test2 ______ { public static void main(String[] args) { Thread t=new Test2(); t.start(); } public void run() { System.out.println("How are you."); } } 程序中下画线处应填入的正确选项是

    A.implements Thread

    B.extends Runnable

    C.implements Runnable

    D.extends Thread


    正确答案:D

  • 第5题:

    以下程序调试结果为:class Base{Base(){int i = 100;System.out.print (i);}}public class Pri extends Base{static int i = 200;public static void main(String argv[]){Pri p = new Pri();System.out.print(i);}}

    A.编译错误

    B.200

    C.100200

    D.100


    正确答案:C

  • 第6题:

    设有程序如下: 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("子类"); } } 其输出结果只有一行。()

    此题为判断题(对,错)。


    答案:错

  • 第7题:

    以下语句能顺利通过编译: abstract class class1 { } public class mainClass { public static void main(String args[]) { class1 cs1=new class1(); } } 。()

    此题为判断题(对,错)。


    答案:错

  • 第8题:

    class One {  public One() { System.out.print(1); }  }  class Two extends One {  public Two() { System.out.print(2); }  }  class Three extends Two {  public Three() { System.out.print(3); }  }  public class Numbers{  public static void main( String[] argv) { new Three(); }  }  What is the result when this code is executed?() 

    • A、 1
    • B、 3
    • C、 123
    • D、 321
    • E、 The code rims with no output.

    正确答案:C

  • 第9题:

    class Bird {  static void talk() { System.out.print("chirp "); }  }  class Parrot extends Bird {  static void talk() { System.out.print("hello "); }  public static void main(String [] args) {  Bird [] birds = {new Bird(), new Parrot()};  for( Bird b : birds)  b.talk();  }  }  结果为:() 

    • A、chirp chirp
    • B、chirp hello
    • C、hello hello
    • D、编译失败

    正确答案:A

  • 第10题:

    现有:      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、  TeStA
    • B、  TeStB
    • C、编译失败
    • D、运行时抛出异常

    正确答案:B

  • 第11题:

    单选题
    class Base {  Base() { System.out.print(“Base”); }  }  public class Alpha extends Base {  public static void main( String[] args ) {  new Alpha();  new Base();  }  }  What is the result?()
    A

     Base

    B

     BaseBase

    C

     Compilation fails.

    D

     The code runs with no output.

    E

     An exception is thrown at runtime.


    正确答案: C
    解析: 暂无解析

  • 第12题:

    单选题
    Which statements, when inserted at the indicated position in the following code, will cause a runtime exception when attempting to run the program?()   class A {}   class B extends A {}   class C extends A {}   public class Q3ae4 {   public static void main(String args[]) {   A x = new A();   B y = new B();   C z = new C();   // insert statement here   }   }
    A

    x = y;

    B

    z = x;

    C

    y = (B) x;

    D

    z = (C) y;

    E

    y = (A) y;


    正确答案: E
    解析: 暂无解析

  • 第13题:

    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();

    }

    }


    正确答案:

     

    错误。在编译时会发生错误(错误描述不同的JVM 有不同的信息,意思就是未明确的

    x 调用,两个x 都匹配(就象在同时import java.util 和java.sql 两个包时直接声明Date 一样)。

    对于父类的变量,可以用super.x 来明确,而接口的属性默认隐含为 public static final.所以可

    以通过A.x 来明确。

  • 第14题:

    下列程序创建了一个线程并运行,横线处应填入的正确代码是( )。 public class Try extends Thread{ public static void main(String args[]){ Thread t=new Try; ; } public void runf System.out.println(”Try!"); } }

    A.t.start

    B.t.class

    C.t.thread

    D.t.static


    正确答案:A
    A。【解析】start是类Thread的方法,其中start方法用于启动线程,使之从新建状态转入就绪状态并进入就绪队列排队,一旦轮到它来享用CPU资源时,就可以脱离创建它的主线程独立地开始自己的生命周期了。

  • 第15题:

    在下列基类的定义中,有无virtual修饰use成员函数的结果将不同,其原因是______。

    当use( )为虚拟函数时的程序执行结果:

    sizeof(A)=8

    sized(B)=12

    sizeof(C)=16

    当use( )非虚拟函数时的程序执行结果:

    sizeof(A)=4

    sized(B)=8

    sizeof(C)=12

    源程序如下:

    include<iostream.h>

    class Grandad

    {

    public:

    Grandad( ):money(10){}

    int money;

    virtual void use( ){}

    };

    class Father:public Grandad

    {

    public:

    Father( ):money(100){}

    int money;

    void use( ){}

    };

    class Son:public Father

    {

    public:

    Son( ):money(300){}

    int money;

    void use( ){}

    };

    void main(void)

    {

    Grandad A;Father B;Son C;

    cout<<"sizeof(A)="<<sizeof(A)<<endl;

    cout<<"sizeof(B)="<<sizeof(B)<<endl;

    cout<<"sizeof(C)="<<sizeof(C)<<endl;

    }


    正确答案:采用虚函数的每个派生类都含有一个指向虚函数表的指针故多4字节。
    采用虚函数的每个派生类都含有一个指向虚函数表的指针,故多4字节。

  • 第16题:

    下列程序的输出结果是

    class Father{

    int m.n;

    Father(int a,int B)

    { m=a;

    n=b

    }

    void show ( ){

    System.out.println("m and n:"+m+" "+n);

    }

    }

    class Son extends Father{

    int p;

    Son (int a,int b,int C)

    { super(a,B) ;

    p=c;

    }

    void show(){supur.show( );

    System.out.println("p:"+p);

    }

    }

    class Test {

    public static void main (String args[ ])

    { Son s:new Son(6,7,8);

    s.show( );

    }

    }

    A.m and n:6 8 p:7

    B.m andn:6 7 p:8

    C.m and n:7 8 p:6

    D.m and n:8 7 p:6


    正确答案:B
    解析:如果你希望访问一个覆盖方法的超类版本,可以通过super来做到这一点,本题中show()的超类版本在子类版本内被调用。

  • 第17题:

    下列程序创建了一个线程并运行,请在下划线处填入正确代码。

    public class Try extends Thread{

    public static void main(String args[]){

    Threadt=new Try();

    【 】;

    }

    public void run(){

    System.out.println(“Try!”);

    }

    }


    正确答案:i
    i

  • 第18题:

    设有程序如下: 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("子类"); } } 其输出结果的第一行是子类。()

    此题为判断题(对,错)。


    答案:错

  • 第19题:

    设有程序如下: 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)可以顺利通过编译。()

    此题为判断题(对,错)。


    答案:错

  • 第20题:

    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、 TestA
    • B、 TestB
    • C、 Compilation fails.
    • D、 An exception is thrown at runtime.

    正确答案:B

  • 第21题:

    Many Scottish names begin with M’,Mc or Mac,which means()

    • A、father of
    • B、sun of
    • C、son of
    • D、some of

    正确答案:C

  • 第22题:

    class Base {  Base() { System.out.print(“Base”); }  }  public class Alpha extends Base {  public static void main( String[] args ) {  new Alpha();  new Base();  }  }  What is the result?()  

    • A、 Base
    • B、 BaseBase
    • C、 Compilation fails.
    • D、 The code runs with no output.
    • E、 An exception is thrown at runtime.

    正确答案:B

  • 第23题:

    单选题
    下列程序的运行结果是(  )。class Shape{ public Shape(){ System.out.print("Shape"); }}class Circle extends Shape{ public Circle(){ System.out.print("Circle"); }}public class Test{ public static void main(String[]args){ Shape d=new Circle(); }}
    A

    Shape

    B

    Circle

    C

    ShapeCircle

    D

    程序有错误


    正确答案: B
    解析:
    继承是面向对象编程的一个主要优点之一,它对如何设计Java类有着直接的影响。该程序首先编写了一个Shape的类,然后又编写一个类Circle去继承Shape类。由于子类拥有父类所有的属性和方法,所以输出的是ShapeCircle。