100普考 計概 - 普考
By Ula
at 2013-05-30T22:55
at 2013-05-30T22:55
Table of Contents
[考題] 國考歷屆考題與考題觀念討論(書裡看到的選這個)請附上想法、出處
出處:如題
下列以C++程式語言撰寫之程式執行後的輸出為何?
#include <iostream>
using namespace std;
class P {
public:
void foo() { cout << 'P'; }
};
class C : public P {
public:
void foo() { cout << 'C'; }
};
int main()
{
P p; C c;
P *pc = &c;
P &rc = c;
p.foo();
c.foo();
pc->foo();
rc.foo();
return 0;
}
(A)PCPP (B)PPPP (C)PCCC (D)CCCC
答案是A
可是請問為什麼c.foo()是印出C ?而不是呼叫父類別P的foo() ?
--
出處:如題
下列以C++程式語言撰寫之程式執行後的輸出為何?
#include <iostream>
using namespace std;
class P {
public:
void foo() { cout << 'P'; }
};
class C : public P {
public:
void foo() { cout << 'C'; }
};
int main()
{
P p; C c;
P *pc = &c;
P &rc = c;
p.foo();
c.foo();
pc->foo();
rc.foo();
return 0;
}
(A)PCPP (B)PPPP (C)PCCC (D)CCCC
答案是A
可是請問為什麼c.foo()是印出C ?而不是呼叫父類別P的foo() ?
--
Tags:
普考
All Comments
By Bennie
at 2013-06-04T11:04
at 2013-06-04T11:04
By Doris
at 2013-06-05T15:34
at 2013-06-05T15:34
By Susan
at 2013-06-07T17:25
at 2013-06-07T17:25
By Quanna
at 2013-06-11T12:38
at 2013-06-11T12:38
By Jacob
at 2013-06-12T19:42
at 2013-06-12T19:42
By Enid
at 2013-06-15T04:41
at 2013-06-15T04:41
By Olive
at 2013-06-17T22:26
at 2013-06-17T22:26
By Delia
at 2013-06-21T19:19
at 2013-06-21T19:19
By Gary
at 2013-06-24T19:57
at 2013-06-24T19:57
By Rae
at 2013-06-29T03:45
at 2013-06-29T03:45
By Rachel
at 2013-07-02T03:39
at 2013-07-02T03:39
By Madame
at 2013-07-06T10:22
at 2013-07-06T10:22
By Hedda
at 2013-07-10T10:37
at 2013-07-10T10:37
By Vanessa
at 2013-07-12T15:00
at 2013-07-12T15:00
By Noah
at 2013-07-15T20:59
at 2013-07-15T20:59
By Vanessa
at 2013-07-16T19:52
at 2013-07-16T19:52
By Rebecca
at 2013-07-19T10:15
at 2013-07-19T10:15
Related Posts
只有高中畢業能考哪些試?
By Yedda
at 2013-05-30T21:15
at 2013-05-30T21:15
小弟的免費線上測驗網站passpass.cc
By Hazel
at 2013-05-30T15:15
at 2013-05-30T15:15
高普考各科報名人數出來了
By Hedda
at 2013-05-29T18:00
at 2013-05-29T18:00
小弟的免費線上測驗網站passpass.cc
By Ula
at 2013-05-29T12:23
at 2013-05-29T12:23
請問稅特考上後六年可以轉任其他職缺嗎?
By Enid
at 2013-05-29T02:02
at 2013-05-29T02:02