instanceOf(obj,class)判断类型是不是指定类或其子类

instanceOf(obj,class)判断类型是不是指定类或其子类


相关考题:

下列程序段中,A_class的成员函数Variance()可求出两数的平方差,请改写该程序段,把Variance()函数从A_class类中分离出来,用友元函数来实现该函数的功能。class A_class {private:intx,y,t;public:A_class(int i,int j):x(i),y(j) {if(yx){t=x;x=y;y=t;}}intVariance(){return x*x-y*y;}//其它函数从略};void main() {A_classA_obj(3,5);coutResult:A_obj.Variance()endl;}

有如下程序#includeusing namespace std;class Obj{static int i;public:Obj(){i++;}~Obj(){i--;}static int getVal(){teturn i;}};int Obj::i=0;void f (){Obj ob2;coutObj obl;F();Obj*ob3=new Obj;coutDelete ob3;cout}程序的输出结果是______。A.232B.231C.222D.221

以下程序的执行结果是【】。 include using namespace std; class base { public: virmal 以下程序的执行结果是【 】。include<iostream>using namespace std;class base{public:virmal void who(){cout<<"Base Class"<<endl;)};class Derivedl:public Base{public:virtual void who(){cout<<"Derivedl Class"<<endl;}};class derived2:public Base{public:virtual void who(){cout<<"Derived2 Class"<<endl;)};int main(int argc,char*argv[]){base obj1,*P;deliVedl obj2;derived2 obj3;p=obj1; p->who();p=obj2; p->who();p=obj3; p->who();return 0;}

( 29 ) 有如下程序 :#includeusing namespace std;class Obj{static int i;public:Obj( ){ i++; }~Obj( ){ i--; }static int getVal( ){ return i;}};int Obj::i=0;void f(){Obj ob2; coutint main( ){Obj ob1;f( );Obj *ob3=new Obj; coutgetVal( );delete ob3; cout return 0;}程序的输出结果是A ) 232B ) 231C ) 222D ) 221

有以下程序 include using namespace std; class MyClass { public: 有以下程序 #include<iostream> using namespace std; class MyClass { public: MyClass(intn) {number=n;} //拷贝构造函数 MyClass (MyClass other) {number=other.number;} ~MyClass(){} private: int number; }; MyClass fun (MyClass p) { MyClass temp(p); return temp; } intmain() { MyClass obj1(10),obj2(0); MyClass obj3(obj1); obj2=fun(obj3); return0; } 程序执行时,MyClass类的拷贝构造函数被调用的次数是A.5B.4C.3D.2

有如下程序: include using namespace std; class Obj { static in 有如下程序: #include <iostream> using namespace std; class Obj { static int i; public: Obj( ){i++;} ~Obj(){i--;} static int getVal( ){ return i;} }; int Obj::i=0; void f() {Obj ob2; cout<<ob2.getVal( ); } int main( ){ Obj ob1; f(); Obj *ob3=ew Obj; cout<<ob3->getVal( ); delete ob3; cout<<Obj::getVal( ); return 0; } 程序的输出结果是A.232B.231C.222D.221

( 31 )若有如下类定义 :class B{void fun1(){}protected:double varl;public:void fun2(){}};class D:public B{protected:void fun3(){}};已知 obj 是类 D 的对象,下列句中不违反类成员访问控制权限的是A ) obj.funl();B ) obj.varl;C ) obj.fun2();D ) obj.fun3();

若有如下类定义: class B { void fun1() { protected: double var1; public: void fun2() { }, class D: public B protected: void fun3() { };已知obj是类D的对象,下列语句中不违反类成员访问控制权限的是A.obj.fun1();B.obj.varl;C.obj.fun2();D.obj.fun3();

下列程序执行结果是 include class A { public: int a; A( ):a(10){tout 下列程序执行结果是#include<iostream.h>class A{ public:int a;A( ):a(10){tout<<a<<endl;}};void main( ){ A obj1;A obj2(obj1);cout<<" "<<obj2.a<<endl;}A.10 10B.编译错误缺少拷贝构造函数C.10 随机数D.随机数随机数

关于下面程序段说法正确的是()。class X { private: int n; public: X(X }; X::X(X A.语句obj2(obj1);的功能是用对象obj2初始化具有相同类类型的对象obj1B.语句obj2(obj1);的功能是用对象obj1初始化具有相同类类型的对象obj2C.X(X&x)函数中不能访问对象的私有成员D.X(X&x)中的&符号可以删除

有如下程序:includeusing namespace std;class TestClass{static int i;public:TestC 有如下程序: #include<iostream> using namespace std; class TestClass{ static int i; public: TestClass(){i++;} ~TestClass(){i--;} static int getVal(){return i;} }; int TestClass::i=0; void f(){TestClass obj2;cout<<obj2.getVal();} int main(){ TestClass obj 1; f(); TestClass *obj3=new TestClass;cout<<obj3->getVal(); delete obj3;cout<<TestClass::getVal(); return 0; } 程序的输出结果是( )。A.232B.221C.222D.231

下列程序的运行结果是______。 include class A { public: virtual void use( ) {cou 下列程序的运行结果是______。include<iostream.h>class A{public:virtual void use( ) {cout<<"in A\n";}};class B:public A{public:virtual void use( ) {cout<<"in B\n";}};class C:public B{public:virtual void use( ){cout"in C\n";}};void main( ){A*obj;bj=new C;obj->use( );delete obj;}

有如下程序:include using namespace std;class Obj { static int i;public:Obj(){i+ 有如下程序:#include <iostream>using namespace std;class Obj { static int i;public: Obj(){i++;} -Obj(){i--;} static int getVal(){return i;} };int Obj::i=0;void f(){Obj ob2; cout<<ob2.getVal(); }hat main(){ Obj ob1; f(); Obj *ob3=new Obj; cout<<ob3->getVal(); delete ob3; cout<<Obj:: getVal(); return (); }程序的输出结果是( )。A.232B.231C.222D.221

设有以下定义和程序:includeclass A1{public:void show1(){cout 设有以下定义和程序: #include<iostream.h> class A1 { public: void show1() { cout<<"class A1"<<end1; } }; class A2:public A1 { public: void show2() { cout<<"class A2"<<end1; } }; class A3:protected A2 { public: void show3() { cout<<"class A1"<<end1; } }; void main() { A1 obj1; A2 obj2; A3 obj3; } 则以下不合语法的调用语句是( )。A.obj1.show1();B.obj2.show1();C.obj3.show1();D.obj2.show2();

若有以下程序: include using namespace std; class Base { public:void who(){ cout 若有以下程序:include <iostream>using namespace std;class Base{public:void who(){cout<<"class Base"<<end1;}};class Derivedl : public Base{public:void who(){cout<<"class Derivedl"<<end1;}};class Derived2 : public Base{public:void who(){cout<<"class Derived2"<<end1;}};int main(){Base *p;Derivedl obj1;Derived2 obi2;p=obj 1;p=obj2;p->who ( );return 0;}则该程序运行后的输出结果是【 】。

以下程序的执行结果是______。 include class base { public: virtual void who(){c 以下程序的执行结果是______。include<iostream.h>class base{public:virtual void who(){cout<<"base class"<<endl:}};class derrvel:public base{public:void who(){cout<<"derivel class"<<endl:}};class derive2;public base{public:void who() {cout<<"derive2 class"<<endl;}};void main(){base obj1,*P;derive1 obj2;derive2 obj3:p=obj1;p->who();p=obj2:p->who();p=obj3;p->who();}

设有以下定义和程序:includeclass A1{public: void show1(){cout 设有以下定义和程序:#include<iostream.h>class A1{public: void show1() { cout<<"class A1"<<endl; } };class A2 : public A1{public: void show2() { cout<<"class A2"<<end1 }};class A3 : protected A2{public: void show3() { cout<<"class A1"<<endl; }};void main(){ A1 obj1; A2 obj2; A3 obj3;} 则以下不合语法的调用语句是A.obj1. showl();B.obj2. showl();C.obj3. showl();D.obj2. show2();

有如下程序: include using namespace std; class Base { private: 有如下程序: #include<iostream> using namespace std; class Base { private: void funl()const {cout<<"funl";} protected: void fun2() const{cout<<"fun2";} public; void fun3() const {cout<<"fun3";} }; class Derived:protected Base { public; void fun4() const {cout<<"fun4";} }; int main() { Derived obj; obj.funl(); //① obj.fun2(); //② obj.fun3(); //③ obj.fun4(): //④ return 0; } 其中有语法错误的语句是A.①②③④B.①②③C.②③④D.①④

有以下程序include using namespace std;class MyClass{public:MyClass(int n) { num 有以下程序#include <iostream>using namespace std;class MyClass{public: MyClass(int n) { number=n; } //拷贝的构造函数 MyClass(MyClass other) {number=other. number; } ~MyClass() { }private: int number;};MyClass fun(MyClass p){ MyClass temp(p); return temp;}int main() MyClass obj 1 (10), obj 2(0); MyClass obi 3 (obj 1); obj2=fun(obj3); return 0;}程序执行时,MyClass 类的拷贝构造函数被调用的次数是( )。A.5B.4C.3D.2

有以下程序:include using namespace std;class Base{public:Base(){}virtual void w 有以下程序: #include <iostream> using namespace std; class Base { public: Base(){} virtual void who() { cout<<"Base Class"<<end1; } ~Base(){} }; class Derivel : public Base { public: void who() { cout<<"Derivel Class"<<end1; } }; class Derive2 : public Base { public: void who () { cout<<"Derive2 Class"<<end1; } }; int main () { Base *p; Derivel obj1; Derive2 obj2; p=obj1; p=obj2; p->who ( ); return 0; } 执行程序后的输出结果是( )。A.Base ClassB.Derivel ClassC.Derive2 ClassD.程序编译时出错

有如下类定义: class B { public:void funl{} private:void fun2{} protected:void fun3{} }; class D:public B j protected:void fun4{} }; 若obj是类D的对象,则下列语句中不违反访问控制权限的是( )。A.obj.fun1;B.obj.fun2;C.obj.tim3;D.ohj.fun4;

若有如下类定义: class B{ void funl(){} protected: double varl: public: void fun2(){} }; class D:public B{ protected: void fun3(){} }; 已知obj是类D的对象,下列语句中不违反类成员访问控制权限的是( )。A.obj.funl();B.obj.varl;C.obj.fun2();D.obj.fun3();

设有以下定义和程序:includeclass A1{public:void show1(){cout 设有以下定义和程序: #include<iostream.h> class A1 { public: void show1() { cout<<"class A1"<<endl; } }; class A2:public A1 { public: void show2() { cout<<"class A2"<<endl; } }; class A3:protected A2 { public: void show3() { cout<<"class A1"<<endl; } }; void main() { A1 obj1; A2 obj2; A3 obi3; } 则以下不合语法的调用语句是( )。A.objl.show1();B.obj2.show1();C.obj3.show1();D.obj2.show2();

下列程序编译错误,是由于划线处缺少某个语句,该语句是______。 include class A { pr 下列程序编译错误,是由于划线处缺少某个语句,该语句是______。include<iostream.h>class A{private:int numl;public:A( ):numl(0){}A(int i):numl(i){}};class B{private:int num2;public:B( ):num2(0){}B(int i):num2(i){}int my_math(A obj1, B obj2);};int B::my_math(A obj1,B obj2){return(obj1.numl+obj2.num2);}void main(void){A objl(4);B obj,obj2(5);cout<<"obj1+obj2:"<<obj.my_math(obj1,obj2);}

设有如下代码:interface IFace{}class CFace implements IFace{}class Base{}public class ObRef extends Base{public static void main(String argv[]){ObRef bj = new ObRef();Base b = new Base();Object obj1 = new Object();IFace obj2 = new CFace();//Here}}则在 //Here处插入哪个代码将不出现编译和运行错误。A.obj1=obj2;B.b=obj;C.obj=b;D.obj1=b;

考虑如下代码:class Tree{}class Pine extends Tree{}class Oak extends Tree{}public class Forest {public static void main( String[] args ) {Tree tree = new Pine();if( tree instanceof Pine )System.out.println( "Pine" );if( tree instanceof Tree )System.out.println( "Tree" );if( tree instanceof Oak )System.out.println( "Oak" );elseSystem.out.println( "Oops" );}}则输出结果中有哪些?A.Pine B.Tree C.Forest D.Oops E.无输出

判断题instanceOf(obj,class)判断类型是不是指定类或其子类A对B错