单选题
C++
2017-03-30
当一个派生类私有继承一个基类时,基类中的所有公有成员和保护成员成为派生类的( )。
A.公有成员
B.私有成员
C.保护成员
D.友元
参考答案
B
答案解析
C++中,对于公有继承,基类成员保持自己的访问级别:基类的public成员为派生类的public成员,基类的protected成员为派生类的proteeted成员,基类的private成员对派生类不可见,所以:在公有继承中,基类中的公有成员对派生类对象可见,基类中的私有成员对派生类对象不可见;对于私有继承,基类的public和protected成员在派生类中为private成员,基类的private成员对派生类不可见,选项B正确。本题答案为B选项。
你可能感兴趣的试题
A.类与类之间可以互为友元
B.类用于描述事物的属性和对事物的操作
C.类与类之间不能有组合关系
D.类与类之间可以通过封装而具有相对独立性
A.px->f( )
B.rx.f( )
C.XX.f( )
D.PP->f( )
A.int GetPrice( ){return price;}
A.int GetPrice( ){return price;}
A.int GetPrice( ){return price;}
B.int GetPrice( )const{return price;}
B.int GetPrice( )const{retum price;}
B.int GetPrice( )const{retum price;}
C.int Piano::GetPrice( ){return price;}
C.int Piano::GetPrice( ){return price;}
C.int Piano::GetPrice( ){return price;}
D.int Piano::GetPrice( )const{return price;}
D.int Piano::GetPrice( )const{retum price;}
D.int Piano::GetPrice( )const{retum price;}