Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

20-21

Object Oriented
Programming
Revision [3]

M.A.S
Part 6 OOP (M.A.S) OOP
1. Which constructor will be called from the object created in the code below?
1. class A
2. {
3. int i;
4. public A()
5. {
6. i=0; Console.WriteLine(i);
7. }
8. public A(int x=0)
9. {
10. i=x; Console.WriteLine(i);
11. }
12. }
13. A obj1=new obj1();
a) Default b) c) Compile d) Run time
constructor Parameterized time error error
constructor
2. Which among the following is correct for the code given below?
1. class A
2. {
3. private A()
4. {
5. }
6. public A(int x)
7. {
8. }
9. }
10. A a=new A();
11. A b=new A(100);
a) Program will give compile time error c) Program will give runtime error
b) Program will run fine d) Program will give logical error
3. What will be the output of the following code?
1. class A{
2. int a;
3. public A(int i){
4. a = i;
5. }
6. public void assign(int i){
7. a = i;
8. }
9. public int R (){
10. return a;
11. }
12. }
13. static void main()
14. {
15. A obj=new A();
16. obj.assign(5);
17. Console.WriteLine(obj.R);
18. }
a) 5 b) 55 c) Error d) none

1|Page M.A.S
4. What will be the output of the following code?
1. class box
2. {
3. int width;
4. int height;
5. int length;
6. int volume;
7. protected void volume()
8. {
9. volume = width*height*length;
10. Console.WriteLine(volume);
11. }
12. }
13. class Output
14. {
15. public static void main(String args[])
16. {
17. box obj = new box();
18. obj.width=5;
19. obj.height=5;
20. obj.length=6;
21. obj.volume();
22. }
23. }
a) 150 b) 200 c) Run time error d) Compilation error

5. What will be the output of the following code?


1. class area
2. {
3. public int width;
4. public int length;
5. public int area;
6. public void area(int width, int length)
7. {
8. this.width = width;
9. this.length = length;
10. }
11.
12. }
13. class Output
14. {
15. public static void main(String args[])
16. {
17. area obj = new area();
18. obj.area(5 , 6);
19. Console.WriteLine(obj.length + " " + obj.width);
20. }
21. }
a) 0 0 b) 5 6 c) 6 5 d) 5 5
6. What will be the output of the following code?
1. class test
2. {
3. int a;
4. int b;
5. public test(int i, int j)
6. {
Part 6 OOP (M.A.S) OOP
7. a = i;
8. b = j;
9. }
10. public void meth(test o)
11. {
12. o.a *= 2;
13. O.b /= 2;
14. }
15. }
16. class Output
17. {
18. public static void main(String args[])
19. {
20. test obj = new test(10 , 20);
21. obj.meth(obj);
22. Console.WriteLine(obj.a + " " + obj.b);
23. }
24. }
a) 10 20 b) 20 10 c) 20 40 d) 40 20
7. What will be the output of the following code?
1. class box
2. {
3. int width;
4. int height;
5. int length;
6. int volume;
7. public box()
8. {
9. width = 5;
10. height = 5;
11. length = 6;
12. }
13. public void volume()
14. {
15. volume = width*height*length;
16. }
17. }
18. class constructor_output
19. {
20. public static void main(String args[])
21. {
22. box obj = new box();
23. obj.volume();
24. Console.WriteLine(obj.volume);
25. }
26. }
a) 100 b) 150 c) 200 d) 250

8. What will be the output of following snippet of code?


1. class number
2. {
3. private int num1;
4. private int num2;
5. public int anumber
6. {
7. get
8. {

1|Page M.A.S
Part 6 OOP (M.A.S) OOP
9. return num1;
10. }
11. set
12. {
13. num1 = value;
14. }
15. }
16. public int anumber1
17. {
18. get
19. {
20. return num2;
21. }
22. set
23. {
24. num2 = value;
25. }
26. }
27. }
28. class Program
29. {
30. public static void Main(string[] args)
31. {
32. number p = new number();
33. p.anumber = 20;
34. number k = new number();
35. k.anumber1 = 40;
36. int m = p.anumber;
37. int t = k.anumber1;
38. int r = p.anumber + k.anumber1;
39. Console.WriteLine(“number = ” +m);
40. Console.WriteLine(“number = ” +t);
41. Console.WriteLine(“sum = ” +r);
42. }
43. }
a) 0 b) Compile time error c) 60 d) None
9. What will be the output of following snippet of code?
1. class number
2. {
3. private int num1 = 60;
4. private int num2 = 20;
5. public int anumber
6. {
7. get
8. {
9. return num1;
10. }
11. set
12. {
13. num1 = value;
14. }
15. }
16. public int anumber1
17. {

1|Page M.A.S
Part 6 OOP (M.A.S) OOP
18. get
19. {
20. return num2;
21. }
22. set
23. {
24. num2 = value;
25. }
26. }
27. }
28. class Program
29. {
30. public static void Main(string[] args)
31. {
32. number p = new number();
33. number k = new number();
34. int m = p.anumber;
35. int t = k.anumber1;
36. int r = p.anumber * k.anumber1;
37. Console.WriteLine(“sum = ” + r);
38. }
39. }
a) 0 b) 120 c) 1200 d) Compile time error
10. What will be the output of following snippet of code?
1. class number
2. {
3. int length = 50;
4. public int number1
5. {
6. get
7. {
8. return length;
9. }
10. set
11. {
12. length = value;
13. }
14. }
15. }
16. class Program
17. {
18. public static void Main(string[] args)
19. {
20. number p = new number();
21. p.number1 = p.number1 + 40;
22. int k = p.number1 * 3 / 9;
23. Console.WriteLine(k);
24. }
25. }
a) 0 b) 180 c) 30 d) Compile time error

1|Page M.A.S
Part 6 OOP (M.A.S) OOP
11. What will be the output of following snippet of code?
1. class number
2. {
3. int length = 60;
4. public int number1
5. {
6. get
7. {
8. return length;
9. }
10. }
11. }
12. class Program
13. {
14. public static void Main(string[] args)
15. {
16. number p = new number();
17. int l;
18. l = p.number1 + 40;
19. int k = l * 3 / 4;
20. Console.WriteLine(k);
21. }
22. }
a) 30 b) 75 c) 80 d) 0

Arrays – struct Set (1)


1. The space required for structure variables is allocated on stack.
2. C#.NET structures are always value types.
3. A structure variable get destroyed when it goes out of scope.
4. A class is a reference type, whereas a struct is a value type.
5. Objects are created using new, whereas structure variables can be created either using new
or without using new.
6. A structure variable will always be created slower than an object.
7. A Structure can be declared within a method.
8. Structs cannot inherit from another struct.
9. struct members cannot be declared as protected.
10. It is an error to initialize an instance field in a struct.
11. Structures generally used to represent user defined data types that consists of small
amount of data in them hence using stack for deceleration of such variables is not
problem.
12. A structure in C# provides a unique way of packing together data of different types.
13. Struct’s data members are ____________ by default.
A.Protected B. Public C. Private D. Default
14. A structure can contain properties.
15. A structure can contain constructors.

1|Page M.A.S
Part 6 OOP (M.A.S) OOP
16. A structure can contain constants.
17. You can define an unlimited number of members inside a structure.
18. Array elements can be of integer type only.
19. The rank of an Array is the total number of elements it can contain.
20. The length of an Array is the number of dimensions in the Array.
21. The default value of numeric array elements is zero.
22. The Array elements are guaranteed to be sorted.
23. Arrays can be rectangular or jagged.
24. Rectangular arrays have similar rows stored in adjacent memory locations.
25. Rectangular arrays do not have an access to the methods of System.Array Class.
26. Arrays in C# are ______ objects
A. Reference B. Logical C. Value D. Arithmetic
27. An ____ is a group of contiguous or related data items that share a common name.
A. Operator B. Integer C. Exponential D. Array
28. Which of the following is/are not types of arrays in C#?
A. Single-Dimensional C. Jazzed arrays
B. Multidimensional D. Jagged arrays
29. Array is a group of elements of same data type.
30. An array contains more than one element.
31. Array elements are stored in memory in continuous or contiguous locations. []
32. An array address is the address of first element of array itself.
33. An array size must be declared if not initialized immediately.
34. An array Index starts with.?
A) -1 B) 0 C) 1 D) 2
35. An array size can not changed once it is created.
36. Array element value can be changed any number of times.
37. To access Nth element of an array students, use students[n-1] as the starting index
is 0.
38. What is the output of C# Program.? static void main() { int a[]; a[4] =
{1,2,3,4}; Console.WriteLine(a[0]); }
A) 1 B) 2 C) 4 D) Compiler error
39. 7) What is the output of C# Program.? static void main() { int a[] =
{1,2,3,4}; int b[4] = {5,6,7,8}; Console.WriteLine("{0},{1}",
a[0], b[0]); }
A) 1,5 B) 2,6 C) 0 0 D) Compiler error
40. 8) What is the output of C# Program.? static void main() { char grade[] =
{'A','B','C'}; Console.WriteLine("GRADE={0}", grade); }
A) GRADE=some address of array C) GRADE=B
B) GRADE=A D) Compiler error
41. What is the output of C# Program.? static void main() { float marks[3] =
{90.5, 92.5, 96.5}; int a=0; while(a<3) { Console.WriteLine(
marks[a]); a++; } }
A) 90.5 92.5 96.5 C) 0.00 0.00 0.00
B) 90.50 92.50 96.50 D) Compiler error

1|Page M.A.S
42. 11) What is the output of C# Program.? static void main() { int a[3] =
{10,12,14}; a[1]=20; int i=0; while(i<3) {
Console.WriteLine(a[i]); i++; } }
A) 20 12 14 C) 10 12 20
B) 10 20 14 D) Compiler error
43. 12) What is the output of C# Program.? static void main() { int a[3] =
{10,12,14}; int i=0; while(i<3) { Console.WriteLine(i[a]); i++; }
}
A) 14 12 10 C) 10 12 14
B) 10 10 10 D) None of the above
44. 14) What is the output of C# Program with arrays.? static void main() { int
a[3] = {20,30,40}; int b[3]; b=a; Console.WriteLine(b[0]); }
A) 20 C) address of 0th element.
B) 30 D) Compiler error
45. An entire array is always passed by ___ to a called function.
A) Call by value C) Address relocation
B) Call by reference D) Address restructure
46. How do you initialize an array in C#?
a) int arr[3] = (1,2,3); c) int arr[3] = {1,2,3};
b) int arr(3) = {1,2,3}; d) int arr(3) = (1,2,3);
47. Size of the array need not be specified, when
A. Initialization is a part of definition C. It is a declaratrion
B. It is a formal parameter D. All of the above
48. An element Referring outside array bounds is a ___?
A. Compile error C. Execution time error
B. Syntax error D. Both A and C
49. Objects in a sequence that have the same type, is called
A. Arrays B. Operators C. Functions D. Stacks
50. Consecutive group of memory locations contains all same name and same type, is
called as
A. Structures B. Arrays C. Classes D. Functions
51. A one dimensional array is always considered as____?
A. Complex B. Sequential C. Linear D. Both C and B
52. Objects in an array is called as
A. Functions of an array C. Indexes of an array
B. Elements of an array D. All of them
53. Example of___ is float []a = {10.2, 33.4, 44.4}
A. Initializing array C. Initializing functions
B. Initializing variables D. None of them
54. Array containing elements are numbered as 0,1,2,3? these numbers are called
A. Subscripts of the array C. Members of an array
B. Index values D. Both A and B
55. Index number of the last element of an array having 9 elements is _______
A. 9 B. Programmer-defined C. 0 D. 8
56. Array is defined as
A. An array is a series of element
B. An array is a series of elements of the same type in contiguous memory locations
Part 6 OOP (M.A.S) OOP
57. An array is a series of elements of the same type placed in non-contiguous memory
locations
58. How we accesses the seventh element stored in array?
A. array[6]; B. array(7); C. array[7]; D. array;
59. Output of the this program will be _____
1. static void main ()
2. {
3. int array[] = {0, 2, 4, 6, 7, 5, 3};
4. int n, result = 0;
5. for (n = 0 ;n < 8 ;n++) {
6. result += array[n];
7. }
8. Console.WriteLine(result);
9. }
A. 25 B. 27 C. 26 D. None
10. Output of this program will be ____?
1. static void main()
2. {
3. int a = 5, b = 10, c = 15;
4. int [] arr = {a, b, c};
5. Console.WriteLine(arr[arr[1] – 8]]);
6. }
A. 18 C. garbage value
B. 15 D. compile time error
7. Output of this program will be ____?
1. static void main()
2. {
3. char []str = “ABC”;
4. Console.WriteLine(str[3]);
5. Console.WriteLine(str);
6. }
A. ABCD B. AB C. ABC D. None
8. Output of this program will be ____?
1. static void main()
2. {
3. int array[] = {10, 20, 30};
4. Console.WriteLine(-2[array]);
5. }
A. -30 C. garbage value
B. -15 D. compile time error
9. Index of the first element starts from 1.
10. Elements of an array cannot be sorted.
11. Index of the first element in an array can be negative.
12. Which of these is an incorrect array declaration?
a) int arr[] = new int[5]; c) int arr[] = new int[5];
b) int [] arr = new int[5]; d) int arr[] = int [5] new;
13. What will be the output of the following code?
int arr[] = new int [5];
Console.WriteLine(arr);
a) 0 b) value stored in arr[0] c) 00000 d) Namespace.Classname
1|Page M.A.S
14. It is necessary to use new operator to initialize an array.
15. Array can be initialized when they are declared.
16. If you don’t initialize a static array, what will be the element set to?
a) Zero c) An undetermined value
b) A floating-point d) None of these.
17. The Object array is created in _____________________
a) Heap memory b) Stack memory c) HDD d) ROM
18. In Array, There is one to one correspondence between set of ________ and set of
values.
A Constants B Memory Locations C Variables D Indices
19. Array with last element 'n' will always have array size equal to _______.
A n+n B n+1 Cn D n-1
20. Array is ______ data type in C# Programming language.
A Derived Data Type C Custom Data Type
B None of these D Primitive Data Type
21. Size of an array is known at ________.
A Run Time B Compile Time
22. What will happen if in a C# program you assign a value to an array element whose
subscript exceeds the size of array?
A The compiler would report an error.
B The array size would appropriately grow.
C The program may crash if some important data gets overwritten.
D The element will be set to 0.
23. C# does not allow arrays of length zero.
24. Arrays in C# are dynamically allocated using the . . . . operator.
A) create B) dynamic C) arrayList D) new
25. If an index value is less than 0 or greater than or equal to 'array name'.length in an
array element access expression, an . . . . . . is thrown.
A) OutOfBoundsException C) IndexOfBoundsException
B) IndexOutOfBoundsException D) ArrayIndexIsOutOfBoundsException
26. To declare a one-dimensional array, you will use this general form
A) type array-name[] = new [size]; C) type array-name[] = new type[size];
B) type array-name[size] = new type[]; D) type array-name[] = type[size];
27. The ith element in the array has an index . . . .
A) i C) i+1
B) i-1 D) none of above
28. In C#, each array object has a readonly field named . . . . that stores the size of the
array.
A) width B) size C) length D) distance
29. A program P reads in 500 integers in the range [0..100] exepresenting the scores of
500 students. It then prints the frequency of each score above 50. What would be the
best way for P to store the frequencies?
A. An array of 50 numbers D. A dynamically allocated array of
B. An array of 100 numbers 550 numbers
C. An array of 500 numbers

You might also like