0% found this document useful (0 votes)
5 views3 pages

X Viva

The document contains multiple choice questions, fill-in-the-blank statements, true or false assertions, and output prediction questions related to constructors in programming. It covers the purpose, characteristics, and types of constructors, as well as logical operations and expressions in code. The document serves as an educational resource for understanding constructors and their usage in programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

X Viva

The document contains multiple choice questions, fill-in-the-blank statements, true or false assertions, and output prediction questions related to constructors in programming. It covers the purpose, characteristics, and types of constructors, as well as logical operations and expressions in code. The document serves as an educational resource for understanding constructors and their usage in programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CONSTRUCTORS

Multiple Choice Questions

1. For which purpose a constructor is used?

1. To initialise the instance variables


2. To provide the instance variables
3. To organise the instance variables
4. To simplify the instance variables.

2. Which of the following statements is false?

1. A constructor has same name as class name.


2. A constructor returns initial value.
3. A constructor is called while creating an object.
4. A constructor is not used for arithmetical and logical operations.

3. A constructor is always:

1. private
2. protected
3. secure
4. public

4. Which constructor initialises data members with default values?

1. Parameterized constructor
2. Non-parameterized constructor
3. Copy constructor
4. Default constructor

5. What is not true for a constructor?

1. It is used only to initialize the data members.


2. It returns a unique value.
3. It may not use parameter.
4. None of the above.

Fill in the blanks

1. A member function having the same name as that of the class name is called constructor.

2. A constructor has no return type.

3. A constructor is used when an object is created


4. A constructor without any argument is known as non-parameterised constructor.

5. Parameterised constructor creates objects by passing value to it.

6. The this keyword refers to the current object.

7. The argument of a copy constructor is always passed by reference.

8. The constructor generated by the compiler is known as default constructor.

State True or False

1. The compiler supplies a special constructor in a class that does not have any constructor.
True

2. A constructor is not defined with any return type.


True

3. Every class must have all types of constructors.


False

4. A constructor is a member method of a class.


True

5. Constructor is used to initialize the data members of a class.


True

6. A constructor may have different name than the class name.


False

7. A constructor is likely to be defined after the class declaration.


False

Predict the output

Question 1

int c = (3<4)? 3*4 : 3+4;

Output

12

Question 2

int a = 14, b = 4; boolean x = (a > b) ? true : false;


Output

true

Question 3

int x = 90;
char c = (x<=90)? 'Z' : 'I';

Output

Question 4

int a = 18; int b = 12;


boolean t = (a > 20 && b < 15)? true : false;

Output

false

Question 5

c = (val + 550 < 1700)? 200: 400;


if: (a) val = 1000 (b) val = 1500

Output

(a) 200
(b) 400

Explanation

Question 6

Given: x += x++ + ++x + --x


Find the value, when x=5.
Answer
23
Reason — The expression is calculated as follows:
x = x + (x++ + ++x + --x) (x = 5)
x = 5 + (5 + ++x + --x) (x = 6)
x = 5 + (5 + 7 + --x) (x = 7)
x = 5 + (5 + 7 + 6) (x = 6)
x = 5 + 18
x = 23

You might also like