已知程序中已经定义了函数test,其原型是int test(int, int, int);,则下列重载形式中正确的是A.char test(int,int,int);B.double test(int,int,double);C.int test(int,int,int=0);D.float test(int,int,float=3.5F);

题目

已知程序中已经定义了函数test,其原型是int test(int, int, int);,则下列重载形式中正确的是

A.char test(int,int,int);

B.double test(int,int,double);

C.int test(int,int,int=0);

D.float test(int,int,float=3.5F);


相似考题
更多“已知程序中已经定义了函数test,其原型是int test(int, int, int);,则下列重载形式中正确的是A.char test(int,int,int);B.double test(int,int,double);C.int test(int,int,int=0);D.float test(int,int,float=3.5F);”相关问题
  • 第1题:

    ( 21 )已知函数 fun 的原型为

    int fun ( int,int,int ) ;

    下列重载函数原型中错误的是

    A ) char fun ( int,int ) ;

    B ) double fun ( int,int,double ) ;

    C ) int fun ( int,char* ) ;

    D ) float fun ( int, int, int ) ;


    正确答案:D

  • 第2题:

    有如下程序: #include(iostream> using namespace std; Class Test { public: Test() {n+=2;} ~Test() {n-=3;) static int getNum() {return n;} private: static int n; }; int Test::n=1; int main() { Test*p=new Test;

    A.n=0

    B.n=1

    C.n=2

    D.n=3


    正确答案:A
    解析: 本题考查的是静态数据成员和静态成员函数。静态数据成员是类中所有对象共享的成员,而不是某个对象的成员。题目中的静态数据成员n的运算具有叠加性,执行“n+=2”和“n-=3”后n的值为0。

  • 第3题:

    有如下程序:includeusing namespace std;class test{private: int a;public: test(

    有如下程序:#include<iostream>using namespace std;class test{private: int a;public: test(){cout<<"constructor"<<endl;} test(int a){cout<<a<<endl;} test(const test&_test) { a=_test.a; cout<<"copy constructor"<<en+dl; } ~test(){cout<<"destructor"<<endl;}};int main(){ test A(3); rerun 0;}运行时输出的结果是

    A.3

    B.constructor destructor

    C.copy constructor destructor

    D.3 destructor


    正确答案:D
    解析:本题考查的知识点是:构造函数和析构函数。一个类可以有多个构造函数,但只能有一个析构函数。每一个对象在被创建的时候,都会隐含调用众多构造函数中的一个,而在被销毁的时候,又会隐含调用唯一的那个析构函数。因此,解此类题目只要找准创建时调用的是哪个构造函数,和对象何时被销毁即可。本题只有主函数中创建了一个对象A,并使用了构造参数3,因此会隐含调用test(int a)这个构造函数,输出一个3。接下来主函数结束,对象A被销毁,所以又隐含调用~test()析构函数,输出一个destructor。故本题应该选择D。

  • 第4题:

    考虑函数原型void test(int a,int b=7,char="*"),下面的函数调用中,属于不合法调用的是()

    A: test(5)

    B: test(5,8)

    C: test(6,"#")

    D: test(0,0,"*")


    正确答案: C

  • 第5题:

    类Test定义如下,将下列______方法插入③行处是不合法的。 ( )①public class Test{②public float Method(float a,float b){}③④}

    A.public float Method(float a,float b,float c){}

    B.public float Method(float c,float d){}

    C.public int Method(int a,int b){}

    D.private float Method(int a,int b,int c){}


    正确答案:B
    解析:该题考查的方法重载。在 Java程序中可以在同一个类中定义多个名称相同的方法,然而这些方法的参数数量和类型却不完全相同,这种现象被成为方法重载。在本题中,选项A是正确的,虽然它的参数的类型和第二行的参数类型相同,但是它的参数数量是不同的;选项B不正确,它的参数类型和参数数量都和第二行的相同;选项C正确,它的参数类型和第二行的参数类型不同;选项D也正确,它的参数类型和数量都不和第二行的相同。

  • 第6题:

    在下列源代码文件Test.java中,正确定义类的代码是( )。

    A.pblic class test { public int x=0; public test(int x) { this. x=x;} }

    B.public class Test { public int x=0; public Test(int x) { this. x=x;} }

    C.public class Test extends T1,T2{ public int x = 0; public Test(int x){ this. x = x; } }

    D.protected class Test extends T2{ public int x = 0; public Test(int x) { this. x = x; } }


    正确答案:B
    解析:本题主要考查类声明格式为[修饰符]class类名[extends父类名][implements类实现的接口列表],选项A中源文件名与程序名不相同,Java不支持多重继承所以选项C错误,选项D中类的访问权限不对,应为public。

  • 第7题:

    已知函数fun的原型为

    int fun(int,int,int);

    下列重载函数原型中错误的是

    A.char fun(int,int);

    B.double fun(int,int,double);

    C.int fun(int,char木);

    D.float fun(int,int,int);


    正确答案:D
    解析:重载函数至少要在参数个数或参数类型上有所不同。选项D)的重载函数只有返回值不同,其他(参数个数及类型)完全相同。因此,本题答案为D)。

  • 第8题:

    类Test定义如下,将下列哪个方法插入③行处是不合法的( )?

    ① public class Test{

    ② public float Method(float a,float B) { }

    ③ ______

    ④ }

    A.public float Method(float a,float b,float C) { }

    B.public float Method(float c,float d){ }

    C.public int Method(int a,int B) { }private float Method(int a,int b,int C) { }

    D.private float Method(int a,int b,int C) { }


    正确答案:B
    解析:本题主要考查方法重载,方法的重载是指多个方法可以享有相同的名字,但参数的数量或类型必须不相同(采用不同的形式参数列表),选项B不符合方法重载的要求。

  • 第9题:

    有如下类定义: class Test { public: Test{a=0;c=0;}//① int f(im A.const{this->a=a;}//② static int g{return a;f//③ void h(int B.{Test:.b=b;};//④ private: int a; static int b; const int C; }; int Test::b=0: 在标注号码的行中,能被正确编译的是( )。

    A.①

    B.②

    C.③

    D.④


    正确答案:D
    只能通过构造函数的参数初始化列表对常数据成员进行初始化,本题中常数据成员为C。①通过默认构造函数初始化c,所以不正确。常成员函数只能引用本类中数据成员,而不能修改它,所以②不正确。静态成员函数由于没有this指针,所以不能访问本类中的非静态成员,所以③错误。

  • 第10题:

    下面程序输出的结果是( )。 include using namespace std; int test(int n1

    下面程序输出的结果是( )。 #include<iostream> using namespace std; int test(int n1,int n2) {return n1 +n2;} float test (int f1,float f2){return f1-f2;} float test(float x,float y){return(x+y)/2;} float test(float x,int y){return(x+y)*2;} void main(){ int a1=10; float a2=2.5f; cout<<test(a1,a2); }

    A.12.5

    B.7.5

    C.6.25

    D.25


    正确答案:B
    解析:此处为函数的重载,第一个参数为int,第二个参数为float,故执行第二个函数。

  • 第11题:

    类Test1定义如下: 1.public class Test1{ 2. public float aMethod(float a,float b){ return 0;} 3. 4.} 将以下哪种方法插入行3是不合法的。()

    • A、public float aMethod(float a, float b,float c){ return 0;}
    • B、public float aMethod(float c,float d){ return 0;}
    • C、public int aMethod(int a, int b){ return 0;}
    • D、private float aMethod(int a,int b,int c){ return 0;}

    正确答案:B

  • 第12题:

    多选题
    给定java代码如下所示,在A处新增下列()方法,是对cal方法的重载。public class Test {  public void cal(int x, int y, int z) { } //A }
    A

    public int cal(int x,int y,float z){return 0;}

    B

    public int cal(int x,int y,int z){return 0;}

    C

    public void cal(int x,int z){}

    D

    public viod cal(int z,int y,int x){}


    正确答案: B,D
    解析: 暂无解析

  • 第13题:

    有如下程序:includeusing namespace std;Class Test{public:Test(){n+=2;}~Test(){n-

    有如下程序: #include<iostream> using namespace std; Class Test { public: Test() {n+=2;} ~Test() {n-=3;} static int getNum() {return n;} private: static int n; }; int Test::n=1; int main() { Test*p=new Test;

    A.n=0

    B.n=1

    C.n=2

    D.n=3


    正确答案:A
    解析: 静态数据成员是类中所有对象共享的成员,而不是某个对象的成员。题中变量n是静态数据成员,对象对其操作的结果具有叠加作用,main函数中先定义了Test的对象*p,然后又delete p,所以对静态数据n进行了两次操作,分别是”n+=2”和”n+=3”,n的初始值是1,那么n最后的值变为0。main函数最后通过调用静态函数getNum得到n的值,并输出。

  • 第14题:

    考虑函数原型void test(int a,int b=7,char z=‘*’),下面的函数调用中,属于不合法调用的是( )。

    A.test(5);

    B.test(5,8);

    C.test(6,’#’);

    D.test(0,0,’x’);


    正确答案:C
    解析: 题中函数声明带有默认参数,那么在C选项的调用中,将会把字符型实参#赋值给整型形参b,这不符合参数传递规则。

  • 第15题:

    在如下源代码文件Test.java中, 哪个是正确的类定义?()

    A.public class test { public int x = 0; public test(int x) { this.x = x; } }

    B.public class Test{ public int x=0; public Test(int x) { this.x = x; } }

    C.public class Test extends T1, T2 { public int x = 0; public Test (int x) { this.x = x; } }

    D.public class


    正确答案:BD

  • 第16题:

    下列程序的运行结果是【 】。 include class test { private: int num; public: tes

    下列程序的运行结果是【 】。

    include <iostream. h>

    class test

    {

    private:

    int num;

    public:

    test()

    int TEST() {return num+100;}

    ~test()

    };

    test::test(){num=0;}

    test::~test(){cout<<"Destructor is active"<<endl;}

    void main()

    {

    test x[3]

    cout<<x[1]. TEST()<<endl;

    }


    正确答案:100
    100 解析:本题比较简单,考查考生基本的类的定义,构造函数以及对象数组的概念。

  • 第17题:

    函数int test(int a,int b=l,int c=0),下列调用不合法的个数是 test(0); test(0,0); test( ); test(0,0,0);

    A.0

    B.1

    C.2

    D.3


    正确答案:C
    解析:如果一个函数中有多个参数,则默认参数应从右到左逐个定义。注意:选项C没有给a传递任何的参数,所以是错误的。注意:函数含有默认参数时的调用方式。

  • 第18题:

    有如下类定义: class Test { public: Test(){a=0;c=0} //① int f(int a)const{this->a=a;} //② static int g(){return a;} //③ void h(int b){Test::b;}; //④ private: int a; static int b; const int C; }; int Test::b=0; 在标注号码的行中,能被正确编译的是( )。

    A.①

    B.②

    C.③

    D.④


    正确答案:D
    解析:此题考查的是类的定义。一个类的长数据成员的初始化只能在成员初始化列表中进行,故选项A) 错误;常成员函数不能更新对象的数据成员,故选项B) 错误;静态成员函数可以直接访问类中说明的静态成员,但不能直接访问类中说明的非静态成员,故选项C) 错误。

  • 第19题:

    有下列程序: include using namespace std; classTest{ public: Test(){n+=2;} ~Test

    有下列程序: #include<iostream> using namespace std; classTest{ public: Test() {n+=2;} ~Test() {n-=3;} static int getNum(){return n;} private: static int n; }; int Test::n=1; int main() { Test*p=new Test

    A.n=0

    B.n=l

    C.n=2

    D.n=3


    正确答案:A
    解析: 语句Test*p=new Test;会调用类的构造函数Test() {n+=2;},使n的值由原来的1变为3,然后delete p调用类的析构函数~Test() {n-=3;},因为n是static型变量,所以会在3的基础上减3使得输出结果为0。

  • 第20题:

    有下列程序:includeusing namespace Std;class Test{public:Test(){n+=2;}~Test(){n-

    有下列程序: #include<iostream> using namespace Std; class Test { public: Test() {n+=2;} ~Test() {n-=3;} static int getNum(){return n;} private: static int n; }; int Test∷n=1; int main()

    A.n=0

    B.n=l

    C.n=2

    D.n=3


    正确答案:A
    解析: 此题考查的是静态数据成员和静态成员函数。静态数据成员是类中所有对象共享的成员,而不是某个对象的成员。题目中的静态数据成员n的运算具有叠加性,执行“n+=2”和“n-=3”后n的值为0。

  • 第21题:

    在下列源代码文件Test.java中, ( )是正确的类定义。

    A.public class test{

    B.public class Test{ public int x=0;public int x=0; public test (intx) public Test (int x){ {this.x=x; this.x=x;} }} }

    C.public class Test extends T1,T2{

    D.protected class Test extends T2{ public int=0;public int x=0; public Test(int x){Public Test (int x){ this.x=x;this.x=x: }} }}


    正确答案:B

  • 第22题:

    如下程序编译时发生错误,错误的原因是show函数实现语句错误,则正确的语句应该为______。

    include<iostream.h>

    class test

    {

    private:

    int hum;

    public:

    test(int);

    void show( );

    };

    test::test(int n){num=n;}

    test::show( ){cout<<num<<endl;}

    void main( )

    {

    test T(10):

    T.show( );

    }


    正确答案:void test::show( ){coutnumendl;}
    void test::show( ){coutnumendl;} 解析:show成员函数的声明和实现不一致,即实现部分应有void修饰符,这样才能编译通过。

  • 第23题:

    单选题
    已知函数fun的原型为int fun(int,int,int);下列重载函数原型中错误的是(  )。
    A

    char fun(int,int);

    B

    double fun(int,int,double);

    C

    int fun(int,char*);

    D

    float fun(int,int,int);


    正确答案: A
    解析:
    重载函数的原则是至少要在参数个数或参数类型上不同。A项正确,参数个数与函数fun不同;B项正确,最后一项参数类型与函数fun不同;C项正确,参数个数与参数类型与函数fun不同;D项错误,只有函数返回类型不同,而其他完全相同,不能作为重载函数来使用。