Java认证考试

public class MethodOver {   public void setVar (int a, int b, float c) {   }   }   Which two overload the setVar method?()A、 Private void setVar (int a, float c, int b) {}B、 Protected void setVar (int a, int b, float c) {}C、 Public int setVar (int a, flo

题目

public class MethodOver {   public void setVar (int a, int b, float c) {   }   }   Which two overload the setVar method?()

  • A、 Private void setVar (int a, float c, int b) {}
  • B、 Protected void setVar (int a, int b, float c) {}
  • C、 Public int setVar (int a, float c, int b) (return a;)
  • D、 Public int setVar (int a, int b, float c) (return a;)
  • E、 Protected float setVar (int a, int b, float c) (return c;)
如果没有搜索结果,请直接 联系老师 获取答案。
如果没有搜索结果,请直接 联系老师 获取答案。
相似问题和答案

第1题:

已知如下类定义: class Base { public Base (){ //... } public Base ( int m ){ //... } protected void fun( int n ){ //... } } public class Child extends Base{ // member methods } 如下哪句可以正确地加入子类中?()

A.private void fun( int n ){ //...}

B.void fun ( int n ){ //... }

C.protected void fun ( int n ) { //... }

D.public void fun ( int n ) { //... }


正确答案:CD

第2题:

类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也正确,它的参数类型和数量都不和第二行的相同。

第3题:

下列选项中的 方法可以正确地加入类Child中,且父类的方法不会被覆盖。 public class Parent{ public int addValue(int a,int b){ int s; s=a+b; return s; } } class Child extends Parent{ }

A.int addValue(int a,int b){∥do something…}

B.public void addValue( ){∥do something…}

C.public int addValue(int a,int b)throws MyException{∥do something…}

D.public float addValue(int a,int b,float b=1.0){∥do something…}


正确答案:B
解析: 选项A的错误就是重写的访问权限比被重写的方法的权限低,而B属于重载,选项 C的错误在于比被重写的方法抛弃了更多种类的异常。选项D中,当只传递两个变量的值时,系统不知道到底调用哪一个方法,因为b为常量,可以不指定,所以只有选项B符合题意。

第4题:

下面哪个方法是 public void example(){...} 的重载方法?

A、private void example( int m){...}

B、public int example(){...}

C、public void example2(){...}

D、public int example(int m, float f){...}


答案:D

第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) { }private float Method(int a,int b,int C) { }

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


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

第6题:

指出下面程序段中的错误,并说明出错原因【 】。

class Location {

int X, Y=20;

protected:

int zeroX, zeroY;

int SetZero(int ZeroX, iht ZeroY);

private:

int length, height;

public:

float radius;

void init(int initX,int initY);

int GetX();

Int GetY();

};


正确答案:int XY=20; 出错不能采用这种方式初始化
int X,Y=20; 出错,不能采用这种方式初始化

第7题:

类testl定义如下: public class test1 { public float amethod(float a,float b){ } }

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

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

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

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


正确答案:B

第8题:

指出下列哪个方法与方法public void add(int a){}为合理的重载方法。()

A public int add(int a)

B public void add(long a)

C public void add(int a,int b)

D public void add(float a)


参考答案BCD

第9题:

下列重载函数中,正确的是( )。

A.void fun(int a,float b);void fun(int C,float d)

B.void fun(int a,float b);void fun(float a,int b)

C.float fun(int a,float b);int fun(int b,float a)

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


正确答案:B

第10题:

指出下列哪个方法与方法public void add(int a){}为错误的重载方法()

A、public int add(int a)

B、public void add(long a)

C、public int add(long a)

D、public void add(float a)


答案:A

更多相关问题