河南成教 / 面向对象程序设计
14[分析题]
#include “iostream.h”
class A{
public:
A( )
{ cout<<”A begins” ; }
~A( )
{ cout<<”A ends”; }
void print( )
{ cout<<”I am A”; }
virtual void show()
{ cout<<”A is great”; }
}
};
class B :public A{
public:
B( )
{ cout<<”B begins” ; }
~B( )
{ cout<<”B ends” ; }
void print ( )
{ cout<<”I am B” ; }
void show()
{ cout<<”B is great” }
};
void main( )
{ A obj_b;
A *p;
p=new B;
p->show();
p=&obj_b;
p->print();
}
14[分析题]
#include “iostream.h”
class A{
public:
A( )
{ cout<<”A begins” ; }
~A( )
{ cout<<”A ends”; }
void print( )
{ cout<<”I am A”; }
virtual void show()
{ cout<<”A is great”; }
}
};
class B :public A{
public:
B( )
{ cout<<”B begins” ; }
~B( )
{ cout<<”B ends” ; }
void print ( )
{ cout<<”I am B” ; }
void show()
{ cout<<”B is great” }
};
void main( )
{ A obj_b;
A *p;
p=new B;
p->show();
p=&obj_b;
p->print();
}
参考答案:
佳题速递: