50 câu hỏi
What is the output of the following code?
21,21
20,21
21,22
compile error
What is the output of the following code?
100
101
none
compile error
The design of classes in a way that hides the details of implementation from the user is known as:
Encapsulation
Information Hiding
Data abstraction
All of the above
Which of the following keywords do you think can be used when declaring static members in a class?
(i) Public
(ii) Private
(iii) Protected
all of above
(i)
(i), (iii)
I want a nonmember function to have access to the private members of a class. The class must declare that function:
friend
inline
static
virtual
The ability to reuse objects already defined, perhaps for a different purpose, with modification appropriate to the new purpose, is referred to as
Information hiding
Inheritance
Redefinition
Overloading
What do you think is the outcome of calling a redefined non-virtual function using a base-class pointer?
The appropriate redefined version of the function will be used
The base-class version of the function will always be used
The outcome is unpredictable
A run-time error will occur
A class member that is to be shared among all objects of a class is called
A const member
A reference parameter
A static member
A function member
What is a base class?
An abstract class that is at the top of the inheritance hierarchy.
A class with a pure virtual function in it.
A class that inherits from another class
A class that is inherited by another class, and thus is included in that class.
A variable that is declared protected:
Is visible only in the subclasses (and not in the class it is declared in)
Is visible only in the class it is declared in
Is visible to all classes, but modifiable only in the class where it is declared
Is visible in the class it is declared in, and all of its sub-classes
What is a destructor?
A function called when an instance of a class is initialized
A function that is called when an instance of a class is deleted
A special function to change the value of dynamically allocated memory
A function that is called in order to change the value of a variable
In protected inheritance:
The public members of the base class become public
The public members of the base class become protected
The protected members of the base class become private
The public members of the base class become inaccessible
If a class declares a variable static, this means:
Each instance of a class will have its own copy of the variable
Changing the variable in one instance will have no effect on other instances of the class
Changing the variable in one instance will have no effect on other instances of the class
Every instance of the class must consider the value of the static variable before initializing
In case of a copy constructor, which of the following is true?
Used to instantiate an object from another existing object
To copy one object to another existing object
Can be a substitute for a ‘=’ operator
All of the above
A class declaring another class as a friend will:
Have wine and cheese with that other friend
Allow that class to declare an instance of it in its list of private variables
Allow the other class (the one declared as friend) to access to the declaring class’s private variables
Allow the class declaring the other as a friend to access the declared class’s private variables
Which of the following can be virtual?
constructors
destructors
static functions
None of the above
Where is an exception generated?
In the catch block
In the throw clause
In the constructor of a class
Only when memory allocation fails
Static member functions ___
can be used without an instantiation of an object
can only access static data
Both 1 and 2 are correct
Neither 1 nor 2 are correct
What makes a class abstract?
The class must not have method
The class must have a constructor that takes no arguments
The class must have a function definition equal to zero
The class may only exist during the planning phase
In the following program, how many times Base’s constructor will be called?
1
2
3
error
In the following code what would be the values of i1 and i2
i1=2 i2=2
i1=2 i2=3
i1=3 i2=2
Error
In the following code, which of the following variables can be accessed in “Friend”?
only a and b
a,b and c
only a
error
What is the output of the following code?
0
5
6
7
What is wrong in the following code?
There is nothing wrong
One cannot have a ‘Base’ pointer to ‘Derived’ since it is not derived publicly
One need a derived class pointer to point to a derived class
One required to code a constructor for Derived
What is the output of the following code?
professor researcher teacher myprofessor
researcher professor teacher myprofessor
myprofessor teacher researcher professor
myprofessor researcher professor teacher
What is the output of the following code?
Parent Parent
Parent Child Child Parent
Child Parent Parent Child
Error
What is wrong in the following code?
There is no error
There is a syntax error in the declaration of “Method”
Class D2 does not have access to “Method”
Class D1 must define “Method”
Quy tắc đặt tên biến nào sau đây là đúng?
Là một chuỗi gồm một hoặc nhiều ký tự chữ, số hoặc ký tự gạch dưới, bắt đầu bằng một ký tự hoặc dấu gạch dưới.
Không chứa các ký hiệu Đểc biệt hoặc dấu cách.
Không trùng với các từ khoá.
Tất cả các quy tắc đầu đúng.
Kích thước của dữ liệu kiểu char là bao nhiêu byte?
1
2
4
8
Khai báo biến nào sau đây là SAI?
double d = 3.14;
int num = 10;
long lint = 8;
short int = 5;
Khai báo nào sau đây là ĐÚNG?
signed a;
sign double d;
unsign int i;
longth t;
Biến toàn cục là gì?
Biến khai báo trong thân một hàm hoặc một khối lệnh.
Biến khai báo trong thân main, hoặc bên ngoài tất cả các hàm.
Cả hai đáp án đầu đúng.
Biến cục bộ là dạng biến gì? Chọn câu trả lời đúng nhất.
Là biến khai báo trong thân hàm main
Là biến khai báo trong thân một khối lệnh
Là biến khai báo trong thân một hàm
Là biến khai báo trong một hàm hoặc một khối lệnh
Chuỗi ký tự (string) là gì?
Các giá trị không phải là số và có độ dài là 1
Các giá trị số lớn hơn 0
Các biến có giá trị true hoặc false
Các giá trị cả chữ và số, nằm trong 2 dấu nháy “” và kết thúc với ký tự null
Lệnh nào sau đây là SAI?
string s = 1234;
string s (“Hello world!”);
string s = “Hello world!”;
Tất cả đầu đúng
Khai báo nào sau đây là SAI?
char c = “a”;
int i = 75ul;
int i = 0013;
int i = 0x4b
Lệnh nào sau đây định nghĩa một hằng giá trị?
const PI = 3.1415;
#define PI 3.1415
#define PI = 3.1415
const float PI;
Đoạn lệnh sau có kết quả bao nhiêu?
Một giá trị bất kỳ
5
7
Lỗi biên dịch
Lệnh nào sau đây là SAI?
cout << 120;
Không có lệnh sai
int x; cout << x;
int age = 33; cout << “My age is “ << age << “.\n”;
Nguyên lý của cấu trúc while là:
Chương trình sẽ lặp đi lặp lại khối lệnh cho đến khi biểu thức điều kiện bằng 0.
Chương trình sẽ lặp đi lặp lại khối lệnh cho đến khi biểu thức điều kiện sai.
Chương trình sẽ lặp đi lặp lại khối lệnh cho đến khi biểu thức điều kiện đúng.
Không có đáp án đúng.
Kết quả đoạn lệnh sau là bao nhiêu?
Lỗi biên dịch
0,1,4,9,
Lặp vĩnh viễn
0,1,4,
Kết quả đoạn lệnh sau là bao nhiêu?
0,1,4,
Lặp vĩnh viễn
Lỗi biên dịch
0,1,4,9,
Kết quả đoạn lệnh sau là bao nhiêu?
Lỗi biên dịch
Lặp vĩnh viễn
0,1,4,
0,1,4,9
Kết quả đoạn lệnh sau là bao nhiêu?
Lặp vĩnh viễn
0,1,2,
Lỗi biên dịch
0,1,
Kết quả đoạn lệnh sau là bao nhiêu? For (int i = 0,n = 5; n != i; i++,n--) cout << i << “,”;
0,1,2,
Lặp vĩnh viễn
Lỗi biên dịch
0,1,
Cách khai báo hàm nào sau đây là đúng?
<Tên hàm> { Khối lệnh }
<Kiểu dữ liệu trả về> <Tên hàm> (Tham số 1, Tham số 2,..) { Khối lệnh}
<Tên hàm> (Tham số 1, Tham số 2,..) { Khối lệnh }
<Kiểu dữ liệu trả về> :<Tên hàm> (Tham số 1, Tham số 2,..) { Khối lệnh}
Thế nào là truyền tham trị? Chọn câu trả lời đúng nhất
Truyền bản sao của tham số vào biến. Tất cả các thay đổi của biến được thực hiện bởi hàm không ảnh hưởng đến giá trị của biến bên ngoài hàm.
Truyền địa chỉ của biến vào hàm.
Truyền giá trị của tham số vào biến.
Truyền bản sao của biến vào hàm chứ không phải là bản thân biến
Thế nào là truyền tham biến? Chọn câu trả lời đúng nhất
Truyền giá trị của tham số vào biến.
Truyền bản sao của tham số vào biến. Tất cả các thay đổi của biến được thực hiện bởi hàm không ảnh hưởng đến giá trị của biến bên ngoài hàm.
Truyền địa chỉ của biến vào hàm.
Truyền bản sao của biến vào hàm chứ không phải là bản thân biến.
Hàm overloaded là những hàm như thế nào?
Các hàm trùng tên nhưng khác về cách khai báo tham số
Các hàm có cùng kiểu dữ liệu trả về
Không có đáp án đúng
Các hàm trùng tham số những khác nhau về tên
Mảng là gì? Chọn câu trả lời đúng nhất
Một chuỗi các phần tử cùng kiểu đặt trên các vị trí bộ nhớ khác nhau, trong đó mỗi phần tử có thể tham chiếu thông qua số chỉ mục và tên mảng.
Một chuỗi các phần tử khác kiểu được đặt trên các vị trí bộ nhớ liên tiếp nhau, trong đó mỗi thành phần có thể được tham chiếu thông qua số chỉ mục và tên mảng.
Một chuỗi các phần tử cùng kiểu được đặt trên các vị trí bộ nhớ liên tiếp nhau, trong đó mỗi thành phần có thể được tham chiếu thông qua số chỉ mục và tên mảng.
Không có đáp án đúng
