下面程序的运算结果是( )。 #include<iostream> using namespace std; class A { public: virtual void fun()=0; }; class B:public A } public: void fun() {cout<<"new file"<<" ";} }; class C:public A { public: void fun() { cout<<"open file"<<" ";} }; void main() { A a, * p; B b;C c; p=&c; p->fun(); p=&b; }
A: new file open file
B: new file new file
C: 编译出错
D: open file new file
A: new file open file
B: new file new file
C: 编译出错
D: open file new file
举一反三
- ( File 类)有如下代码: public class TestFile{ public static void main(String args[]){ File file = new File(“chp1 1 /corejava.txt”); } } 请选择一个正确答案:
- 有如下程序: #include<iostream> using namespace std; class A public: virtual void func1()cout<<"A1"; void func2()cout<<"A2"; ; class B:public A public: void func1()cout<<"B1"; void func2()cout<<"B2"; ; int main() A: A*p=new B; B: p->func1(); C: p->func2(); D: delete p; E: retum 0;执行这个程序的输出结果是______。A.B1B2 F: A1A2 G: B1A2 H: A1B2
- 下列程序运行结果是 。class A{public:virtual void funcl(){cout[< "A1";}void func2(){cout<< "A2";}};class B: public A{public:void func1(){cout<< "B1";}void func2(){cout<< "B2";}};int main(){A *p=new B;p-]funcl();p->func2();return 0;}
- 如果在一台 PC 机的c:\source目录运行如下代码: import java.io.*; class Path { public static void main(String[] args) throws Exception { File file = new File('Ran.test'); System.out.println(file.getAbsolutePath()); } } 则,期望的输出结果为?
- 假设在E盘下的cn文件夹中有文件abc.txt,则下列代码的运行结果为 class Example { public static void main(String[] args) { File file = new File("E:\cn"); // 这是一个代表目录的File对象 if (file.exists()) { System.out.println(file.delete()); } } }