多选题class BaseClass{  private float x= 1.0f;  protected void setVar (float f) {x = f;}  } class SubClass extends BaseClass   {  private float x = 2.0f;  //insert code here 16. }   Which two are valid examples of method overriding?()AVoid setVar(float f) {x

题目
多选题
class BaseClass{  private float x= 1.0f;  protected void setVar (float f) {x = f;}  } class SubClass extends BaseClass   {  private float x = 2.0f;  //insert code here 16. }   Which two are valid examples of method overriding?()
A

Void setVar(float f) {x = f;}

B

Public void setVar(int f) {x = f;}

C

Public void setVar(float f) {x = f;}

D

Public double setVar(float f) {x = f;}

E

Public final void setVar(float f) {x = f;}

F

Protected float setVar() {x=3.0f; return 3.0f; }


相似考题
更多“class BaseClass{  private float x= 1.0f;  protected void set”相关问题
  • 第1题:

    下列程序的执行结果是______。 include class Student { public: Student(int xx){x=

    下列程序的执行结果是______。

    include<iostream.h>

    class Student

    {

    public:

    Student(int xx){x=xx;}

    virtual float calcTuition( );

    protected:

    int x;

    };

    float Studertt::calcTuition( )

    {

    return float(x*x);

    }

    class GraduateStudent:public Student

    {

    public:

    GraduateStudent(int xx):Student(xx){}

    float calcTuition( );

    };

    float Graduatestudent::calcTuition( )

    {

    return float(x*2);

    }

    void main( )

    {

    Student s(20);

    GraduateStudent gs(30);

    cout<<s.calcTuition( )<<" "<<gs.calcTuition( )<<endl;

    //计算学生s和研究生gs的学费

    }


    正确答案:400 60
    400 60

  • 第2题:

    12 一个给定的数值由左边开始升位到右边第 N 位,如

    0010<<1 == 0100

    或者

    0001 0011<<4 == 0011 0000

    请用 C 或者 C++或者其他 X86 上能运行的程序实现。

    -----------------------------------------------------------------------------

    -----------------------------------

    附加题(只有在完成以上题目后,才获准回答)

    In C++, what does "explicit" mean? what does "protected" mean?

    explicit

    C++ Specific

    This keyword is a declaration specifier that can only be applied to

    in-class constructor declarations. Constructors declared explicit will not

    be considered for implicit conversions. For example:

    class X {

    public:

    explicit X(int); //legal

    explicit X(double) { //legal // ... }

    };

    explicit X::X(int) {} //illegal

    An explicit constructor cannot take part in implicit conversions. It can

    only be used to explicitly construct an object. For example, with the class

    declared above:

    void f(X) {}

    void g(int I)

    {

    f(i); // will cause error

    }

    void h()

    {

    X x1(1); // legal

    }

    The function call f(i) fails because there is no available implicit

    conversion from int to X.

    Note It is meaningless to apply explicit to constructors with multiple

    arguments, since such constructors cannot take part in implicit conversions.

    END C++ Specific

    protected

    C++ Specific —>

    protected: [member-list]

    protected base-class

    When preceding a list of class members, the protected keyword specifies

    that those members are accessible only from member functions and friends of

    the class and its derived classes. This applies to all members declared up

    to the next access specifier or the end of the class.

    When preceding the name of a base class, the protected keyword specifies

    that the public and protected members of the base class are protected

    members of the derived class.

    Default access of members in a class is private. Default access of members

    in a structure or union is public.

    Default access of a base class is private for classes and public for

    structures. Unions cannot have base classes.

    For related information, see public, private, friend, and Table of Member

    Access Privileges.

    END C++ Specific

    Example

    // Example of the protected keyword

    class BaseClass {

    protected: int protectFunc();

    };

    class DerivedClass : public BaseClass

    { public:

    int useProtect() { protectFunc(); } // protectFunc accessible from

    derived class

    };

    void main()

    {

    BaseClass aBase;

    DerivedClass aDerived;

    aBase.protectFunc(); // Error: protectFunc not accessible

    aDerived.protectFunc(); // Error: protectFunc not accessible in derived

    class } How do you code an infinite loop in C?


    正确答案:
     

  • 第3题:

    下面程序中错误之处是 ______。 include classA{private:intxl;protected:intx2;publ

    下面程序中错误之处是 ______。

    include<iostream.h>

    class A{

    private:

    int xl;

    protected:

    int x2;

    public:

    int x3;

    };

    class B: public A{

    private:

    int b1;

    protected:

    int b2;

    public:

    int b3;

    void disp(){cout<<x1<<b2<<end1;} //A

    void set(int i){x3=i;} //B

    };

    void main()

    B bb;

    bb. a3=10 //C

    bb. b3=10 //D

    }


    正确答案:√
    1

  • 第4题:

    若有以下程序:include using namespace std;class Base{private: int x;protected: i

    若有以下程序: #include <iostream> using namespace std; class Base { private: int x; protected: int y; public: int z; void setx(int i) { x=i; int getx () { return x; } }

    A.1,2,3,4

    B.产生语法错误

    C.4,3,2,1

    D.2,3,4,5


    正确答案:A
    解析:本题考核私有继承中类成员的访问权限。当类的继承方式为私有继承时,基类公有成员和保护成员都以私有成员属性出现在派生类中。私有派生类的成员对其基类成员的访问权和公共派生的方式相同,但是,由私有派生的类声明的对象,不能访问任何基类的成员。本题中,基类Base中的保护成员y和公有成员setx和getx,经过私有继承以后,称为派生类Inherit的私有成员,所以可以在派生类Inherit的函数成员中对它们进行访问。类Inherit中的函数成员setvalue和display都是公有成员,所以可以通过Inherit的对象对它们进行访问。本程序的功能是对类中各数据成员进行赋值,然后查看赋值是否正确。

  • 第5题:

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

    正确答案:A,C

  • 第6题:

    Given:  1. public class Method Over {  2. public void set Var (int a, int b, float c) {  3. }  4. }   Which two overload the set Var method()?

    • A、 private void set Var(int a, float c, int b) {}
    • B、 protected void set Var(int a, int b, float c) {}
    • C、 public int set Var(int a, float c, int b) {return a:}
    • D、 public int set Var(int a, int b, float c) {return a:}
    • E、 protected float set Var(int a, int b, float c) {return c:}

    正确答案:A,C

  • 第7题:

    public class SyncTest (   private int x;   private int y;   private synchronized void setX (int i) (x=1;)   private synchronized void setY (int i) (y=1;)   public void setXY(int 1)(set X(i); setY(i);)   public synchronized Boolean check() (return x !=y;)    )   Under which conditions will check () return true when called from a different class?

    • A、 Check() can never return true.  
    • B、 Check() can return true when setXY is called by multiple threads.  
    • C、 Check() can return true when multiple threads call setX and setY separately.  
    • D、 Check() can only return true if SyncTest is changed to allow x and y to be set separately.

    正确答案:B

  • 第8题:

    public class MethodOver {   private int x, y;   private float z;   public void setVar(int a, int b, float c){   x = a;   y = b;   z = c;   }   }   Which two overload the setVar method?()

    • A、 void setVar (int a, int b, float c){  x = a;  y = b;  z = c;  }
    • B、 public void setVar(int a, float c, int b) {  setVar(a, b, c);  }
    • C、 public void setVar(int a, float c, int b) {  this(a, b, c);  }
    • D、 public void setVar(int a, float b){  x = a;  z = b;  }
    • E、 public void setVar(int ax, int by, float cz) {  x = ax;  y = by;  z = cz;  }

    正确答案:B,D

  • 第9题:

    多选题
    Given:  1. public class Method Over {  2. public void set Var (int a, int b, float c) {  3. }  4. }   Which two overload the set Var method()?
    A

    private void set Var(int a, float c, int b) {}

    B

    protected void set Var(int a, int b, float c) {}

    C

    public int set Var(int a, float c, int b) {return a:}

    D

    public int set Var(int a, int b, float c) {return a:}

    E

    protected float set Var(int a, int b, float c) {return c:}


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

  • 第10题:

    多选题
    public class MethodOver {   private int x, y;   private float z;   public void setVar(int a, int b, float c){   x = a;   y = b;   z = c;   }   }   Which two overload the setVar method?()
    A

    void setVar (int a, int b, float c){  x = a;  y = b;  z = c;  }

    B

    public void setVar(int a, float c, int b) {  setVar(a, b, c);  }

    C

    public void setVar(int a, float c, int b) {  this(a, b, c);  }

    D

    public void setVar(int a, float b){  x = a;  z = b;  }

    E

    public void setVar(int ax, int by, float cz) {  x = ax;  y = by;  z = cz;  }


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

  • 第11题:

    多选题
    1. class BaseClass {  2. private float x = 1.of;  3. protected float getVar() { return x; }  4. }  5. class SubClass extends BaseClass {  6. private float x = 2.Of;  7. // insert code here 8. }   Which two are valid examples of method overriding when inserted at line 7?()
    A

    float getVar() { return x; }

    B

    public float getVar() { return x; }

    C

    public double getVar() { return x; }

    D

    protected float getVar() { return x; }

    E

    public float getVar(float f) { return f; }


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

  • 第12题:

    单选题
    1. abstract class AbstractIt {  2. abstract float getFloat();  3. }  4. public class AbstractTest extends AbstractIt {  5. private float f1 = 1.0f;  6. private float getFloat() { return f1; }  7. }  What is the result?()
    A

     Compilation succeeds.

    B

     An exception is thrown.

    C

     Compilation fails because of an error at line 2.

    D

     Compilation fails because of an error at line 6.


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

  • 第13题:

    有以下程序:include using namespace std;class A{private: int x,y;public: void se

    有以下程序: #include <iostream> using namespace std; class A { private: int x,y; public: void set (int i,int j) { x=i; y=j; } int get_y() { return y; } }; class box { private: int length,width; A label; public: void set(int 1,int w, int s,int p) { length=1; width=w; label.set(s,p); } int get_area() { return length*width; } }; int main() { box small; small.set(2,4,1,35); cout<<small.get_area()<<end1; return 0; } 运行后的输出结果是( )。

    A.8

    B.4

    C.35

    D.70


    正确答案:A
    解析:本题考核成员对象的应用。类box的成员函数set()为设置对象的坐标值和对象的长、宽值。成员函数setarea返回该对象的面积。程序最后输出为8。

  • 第14题:

    若有以下程序:include using namespace std;class A{private: int x;protected: int

    若有以下程序: #include <iostream> using namespace std; class A { private: int x; protected: int y; public: int z; void setx(int i) { x=i; } int getx () { return x; }; class B : protected A { public: void setvalue(int a, int b, int c) { setx (a); y=b; z=c; } void display() { cout<<getx ( ) <<", "<<y<<", "<<z<<", "<<end1; } }; int main () { B obj; obj.setvalue(5, 6, 7); obj.display ( ); return 0; } 程序运行后的输出结果是( )。

    A.产生语法错误

    B.7,6,5

    C.5,6,7

    D.7,5,6


    正确答案:C
    解析:本题考核保护继承中对类成员的访问权限。①在保护继承中,基类公有成员和保护成员都以保护成员身份出现在派生类中,而基类私有成员不可访问。②基类的公有成员和保护成员被继承以后作为派生类的保护成员,这样,派生类的其他成员可以直接访问它们。③由保护派.生的类声明的对象,不能访问任何基类的成员。在本题中,基类A中的数据成员y和函数setx,经过保护继承以后,在派生类B中成为保护成员,派生类B的对象不能访问它们。而派生类B中的函数setvalue和display都是公有成员,可以通过对象对它们进行访问。所以程序中对各成员的访问是正确的。本程序的功能是对类中各数据成员进行赋值,然后查看赋值是否正确。

  • 第15题:

    请找出下列程序中错误之处 ______。 include classA{private: intx1;protected: int

    请找出下列程序中错误之处 ______。

    #include<iostream.h>

    class A{

    private:

    int x1;

    protected:

    int x2;

    public:

    int x3;

    };

    class B:public A{

    private:

    int y1;

    protected:

    int y2;

    public:

    int y3;

    void disp(){cout<<x1<<y1<<end1:} //A

    void set(int i) {x2=i;} //B

    };

    void main() {

    B bb;

    bb.x3=10; //C

    bb.y3=10; //D

    }

    A.A

    B.B

    C.C

    D.D


    正确答案:A

  • 第16题:

    1. class BaseClass {  2. private float x = 1.of;  3. protected float getVar() { return x; }  4. }  5. class SubClass extends BaseClass {  6. private float x = 2.Of;  7. // insert code here 8. }   Which two are valid examples of method overriding when inserted at line 7?() 

    • A、 float getVar() { return x; }
    • B、 public float getVar() { return x; }
    • C、 public double getVar() { return x; }
    • D、 protected float getVar() { return x; }
    • E、 public float getVar(float f) { return f; }

    正确答案:B,D

  • 第17题:

    1. abstract class AbstractIt {  2. abstract float getFloat();  3. }  4. public class AbstractTest extends AbstractIt {  5. private float f1 = 1.0f;  6. private float getFloat() { return f1; }  7. }  What is the result?() 

    • A、 Compilation succeeds.
    • B、 An exception is thrown.
    • C、 Compilation fails because of an error at line 2.
    • D、 Compilation fails because of an error at line 6.

    正确答案:D

  • 第18题:

    abstract class abstrctIt {   abstract float getFloat ();   }   public class AbstractTest extends AbstractIt {   private float f1= 1.0f;   private float getFloat () {return f1;}   }   What is the result? ()

    • A、 Compilation is successful.
    • B、 An error on line 6 causes a runtime failure.
    • C、 An error at line 6 causes compilation to fail.
    • D、 An error at line 2 causes compilation to fail.

    正确答案:C

  • 第19题:

    class BaseClass{  private float x= 1.0f;  protected void setVar (float f) {x = f;}  }  class SubClass extends BaseClass   {  private float x = 2.0f;  //insert code here  }   Which two are valid examples of method overriding?()        

    • A、 Void setVar(float f) {x = f;}
    • B、 Public void setVar(int f) {x = f;}
    • C、 Public void setVar(float f) {x = f;}
    • D、 Public double setVar(float f) {x = f;}
    • E、 Public final void setVar(float f) {x = f;}
    • F、 Protected float setVar() {x=3.0f; return 3.0f; }

    正确答案:C,E

  • 第20题:

    用于定义类成员的访问控制权的一组关键字是()。

    • A、class,float,double,public
    • B、float,boolean,int,long
    • C、char,extends,float,double
    • D、public,private,protected

    正确答案:D

  • 第21题:

    多选题
    public abstract class Shape {  private int x;  private int y;  public abstract void draw();  public void setAnchor(int x, int y) {  this.x = x;  this.y = y;  }  }  Which two classes use the Shape class correctly?()
    A

    public class Circle implements Shape { private int radius; }

    B

    public abstract class Circle extends Shape { private int radius; }

    C

    public class Circle extends Shape { private int radius; public void draw(); }

    D

    public abstract class Circle implements Shape { private int radius; public void draw(); }

    E

    public class Circle extends Shape { private int radius;public void draw() {/* code here */} }

    F

    public abstract class Circle implements Shape { private int radius;public void draw() { / code here */ } }


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

  • 第22题:

    多选题
    class BaseClass{  private float x= 1.0f;  protected void setVar (float f) {x = f;}  }  class SubClass extends BaseClass   {  private float x = 2.0f;  //insert code here  }   Which two are valid examples of method overriding?()
    A

    Void setVar(float f) {x = f;}

    B

    Public void setVar(int f) {x = f;}

    C

    Public void setVar(float f) {x = f;}

    D

    Public double setVar(float f) {x = f;}

    E

    Public final void setVar(float f) {x = f;}

    F

    Protected float setVar() {x=3.0f; return 3.0f; }


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

  • 第23题:

    多选题
    class BaseClass{   private float x= 1.0f;   protected void setVar (float f) {x = f;}   }   class SubClass exyends BaseClass {   private float x = 2.0f;   //insert code here  8. }   Which two are valid examples of method overriding?()
    A

    Void setVar(float f) {x = f;}

    B

    Public void setVar(int f) {x = f;}

    C

    Public void setVar(float f) {x = f;}

    D

    Public double setVar(float f) {x = f;}

    E

    Public final void setVar(float f) {x = f;}

    F

    Protected float setVar() {x=3.0f; return 3.0f; }


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

  • 第24题:

    单选题
    abstract class abstrctIt {  abstract float getFloat ();  } public class AbstractTest extends AbstractIt { private float f1= 1.0f;  private float getFloat () {return f1;}  }   What is the result?()
    A

     Compilation is successful.

    B

     An error on line 6 causes a runtime failure.

    C

     An error at line 6 causes compilation to fail.

    D

     An error at line 2 causes compilation to fail.


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