单选题
C++
题号 #4238635
当一个派生类私有继承一个基类时,基类中的所有公有成员和保护成员成为派生类的( )。
参考答案
B
答案解析
C++中,对于公有继承,基类成员保持自己的访问级别:基类的public成员为派生类的public成员,基类的protected成员为派生类的proteeted成员,基类的private成员对派生类不可见,所以:在公有继承中,基类中的公有成员对派生类对象可见,基类中的私有成员对派生类对象不可见;对于私有继承,基类的public和protected成员在派生类中为private成员,基类的private成员对派生类不可见,选项B正确。本题答案为B选项。
你可能感兴趣的试题
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;}