1. Which of the following is an illegal array initialization statement?

a) var n = [ 10, 20, 30, 40, 50 ];

b) var n = new Array( 10, 20, 30, 40, 50 );

c) var n[ 10, 20, 30, 40, 50 ];

d) var n = new Array( 5 );

for ( var i = 1; i <= 5; i++ )

n[ i ] = i * 10 ;

Ans: c

2. The first statement below ______the array while the second statement ______the array.

var c;

c = new Array( 12 );

a) declares, initializes

b) initializes, declares

c) declares, allocates

d) allocates, declares

Ans: c

3. What does the following code do?

for ( var col = 0; col < a[ 2 ].length; ++col )
a[ 2 ][ col ] = 0;

a) Sets the rows and columns to zero.

b) Sets the rows to zero.

c) Sets the columns to zero.

d) Sets all the elements in row 2 to zero.

Ans: d

4. Suppose that str1, str2, and str3 are string variables. After the following statements execute, the value of str3 is '____'.

str1 = 'abc'; str2 = 'xyz'; str3 = str1 + '-' + str2;

a. abc

b. xyz

c. abc-xyz

d. xyz-abc

Ans: c

5. Consider a class definition. Which of the following class variable declarations of that class is correct?

a. rectangle rectangleType;

b. class rectangleType rectangle;

c. rectangleType rectangle;

d. rectangle rectangleType.area;

ans:c

6. Consider the accompanying class definition, and the declaration: rectangleTypebigRect; Which of the following statements is correct?

a. rectangleType.print();

b. rectangleType::print();

c. bigRect.print();

d. bigRect::print();

ans:c

7. Suppose that x and y are int variables, z is a double variable, and the input is: 28 32.6 12 Choose the values of x, y, and z after the following statement executes: cin » x » y » z;
a x = 28, Y = 32, z = 0.6
b. x = 28, Y = 32, z = 12.0
c. x = 28, Y = 12, z = 32.6
d. x = 28, Y = 12, z = 0.6

ANS: A x = 28, Y = 32, z = 0.6

8. assume that a two dimensional type int array called samplearray of length 5 in both dimensions , has been declared and initialized. The following code sets the elements of the array to store the product of its subscripts. Which of the following is the correct missing statement?

Samplearray[i][j] =i+j

Samplearray[i][j]= pow(i,j)

Samplearray[I,j] =i*j

Samplearray[i][j]= i*j

Ans:d

9.Which of the following is part of an object?

a.) Methods

b.) Properties

c.) Instances

d.) Both a and b.

e.) All of the above.

Ans: d

10.Encapsulation makes it easier to:

a.) reuse and modify existing modules of code.

b.) write and read code by sharing method names.

c.) hide and protect data from external code.

d.) Both a and b.

e.) All of the above.

Ans: c

11.Inheritance makes it easier to:

a.) reuse and modify existing modules of code.

b.) write and read code by sharing method names.

c.) hide and protect data from external code.

d.) Both a and b.

e.) All of the above.

Ans: a

12.Polymorphism makes it easier to:

a.) reuse and modify existing modules of code.

b.) write and read code by sharing method names.

c.) hide and protect data from external code.

d.) Both a and b.

Ans: b

13. When a base class is changed:

a.) there is no effect on the derived class.

b.) the derived class changes when the key word Overridden is used.

c.) only the methods of the derived class change.

d.) only the properties of the derived class change.

e.) the derived class automatically changes.

Ans: e

14. Which statements are not correct about Objects?

  1. An Object is an instance of a class
  2. Objects can access both instance and static data
  3. All classes extend the Object class
  4. Objects do not permit encapsulation

Ans: d

15. If an attribute is private, which methods have access to it?

  1. Only those defined in the same class.
  2. Only static methods in the same class.
  3. Only instance methods in the same class.
  4. Only classes in the same package.

Ans: a

16. What is an aggregate object?

  1. An object instance that has only static methods.
  2. An object instance that has only primitive attributes.
  3. An object instance that contains other objects.
  4. An object that has only primitive attributes and instances methods.

Ans: c

  1. Which of the following is not true about object-oriented design?

a) The focus is on data and associated operations.

b) Data plays the primary role; control flow is secondary.

c) The top-level algorithm is designed first.

d) a and c above

e) none of the above (all of the statements are true)

Ans: c

  1. Putting data and function together means ______a)encapsulation b) inheritance c) abstracting. d) modularization

Ans: a

  1. In Object programming language, the ADT should contain a) private data and private interface. b) Public data and public interface. c) Private data and public interface. d) public data and private interface

Ans: c

  1. Which of the following is not a part of OOP?

a) Encapsulation

b) Recursion

c) Polymorphism

d) Inheritance

Ans: b