Section 1

Preview this deck

a

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 1, 2020

Cards (54)

Section 1

(50 cards)

a

Front

66. If a class has a static constructor then it is automatically called when the class is loaded. Static constructors cannot be invoked explicitly. [0.5] a) True b) False

Back

a d

Front

73. Which of the following statements are true? [1.0] a) A static constructor is a member that implements the actions required to initialize a class. d) A static constructor cannot have accessibility modifiers. b) Static constructors may or may not take parameters. e) A static constructor for a class is called automatically when the object is accessed. c) A static constructor can have public as a accessibility modifiers

Back

d

Front

84. What is the output of the following code? [2.0] public class Test{ public Test(int i){ System.Console.WriteLine("Test(" +i +")"); } } public class Q12{ static Test t1 = new Test(1); Test t2 = new Test(2); static Test t3 = new Test(3); public static void Main(){ Q12 Q = new Q12(); } } a) Test(1) Test(2) Test(3) c) Test(2) Test(1) Test(3) b) Test(3) Test(2) Test(1) d) Test(1) Test(3) Test(2)

Back

c

Front

92. What will be printed to standard output? class Super{ public int index = 5; public virtual void printVal() { System.Console.WriteLine( "Super" ); } } class Sub : Super{ int index = 2; public override void printVal() { System.Console.WriteLine( "Sub" ); } } public class Runner { public static void Main( ) { Super sup = new Sub(); System.Console.WriteLine( sup.index + "," ); sup.printVal(); } } [2.5] a) The code will not compile. c) The code compiles and "5, Sub" is printed on the standard output. b) The code compiles and "5, Super" is printed on the standard output. d) The code compiles and "2, Super" is printed on the standard output.

Back

c

Front

64. Static constructor has _______ parameter/s. [0.5] a) Only one c) no b) One or more

Back

b

Front

95. Which of the following is a valid method declaration? a) public static virtual void Display() { } c) public void virtual Display(){} b) public virtual void Display(){} d) public virtual static void Display() { }

Back

a c

Front

75. Which of the following statements are true with respect to Static constructors. a) Static constructors cannot take parameters. d) Static constructors can be called explicitly or implicitly. b) Static constructors can have accessibility modifiers. e) Static constructors are called when the class is loaded. c) Static constructors cannot be called explicitly.

Back

b

Front

99. The ______ method is used to assign some value to a data member in a class. a) value c) get b) set d) find

Back

b

Front

59. int myVar=3; if (myVar<5) if(myVar<3) Console.WriteLine("<3"); else if (myVar>2) Console.WriteLine(">2"); else Console.WriteLine("Other"); What will appear on the standard output? [2.5] a) <3 c) Other b) >2 d) No output

Back

c

Front

100. public class A:B,C,D{ } The above code represents ______ [0.5] a) multilevel interface c) multiple interface b) hierarchical interface d) multiple inheritance

Back

c

Front

89. //.Inconsistent accessibility: base class 'Test' is less //accessible than class 'Q3' Æ lỗi dòng 7 1. using System; 2. class Test { 3. void show() { 4. Console.WriteLine("non-static method in Test"); 5. } 6. } 7. public class Q3 : Test { 8. static void show() { 9. Console.WriteLine("Overridden non-static method in Q3"); 10. } 11. public static void main(String[] args) { 12. Q3 a = new Q3(); 13. Test t = new Test(); 14. } } The following code will give [2.5] a) Compilation error at line 8. c) No compilation error, but runtime exception at line 8. b) Compilation error at line 13. d) No compilation error, but runtime exception at line 13.

Back

d

Front

82. At least one _______ constructor must be declared to suppress the automatic generation of a default constructor. [1.5] a) Default c) Private b) Static d) Parameterized

Back

a

Front

78. Which of the following statements is correct for a method, which is overriding the following method: public void add(int a) {...}Select the most appropriate answer [1.5] a) the overriding method must return void c) the overriding method can return whatever it likes b) the overriding method must return int

Back

a b

Front

45. How can you initialize an array of three Boolean values? [1.5] a) bool[] b=new bool[3]; c) bool[3] b={true,true,true}; b) bool[] b={true,true,true}; d) bool[3] b=new bool[3]={true,true,true}; 46. using System; class MyClass { int Var1=1; int Var2; public static void Main(){ int LocalVar=3; MyClass m1=new MyClass(); Console.WriteLine(m1.Var1+m1.Var2+LocalVar); } } The output of above code will be: [1.5] a) 4 c) The code does not compile because local variable is not initialized correctly. b) 0 d) The code does not compile because Var2 is not initialized.

Back

b

Front

52. For decimal, the default value is [2.0] a) 0.0d b) 0.0m.

Back

a

Front

97. Abstract class cannot be directly instantiated but it can be used to create object references. [0.5] a) True b) False

Back

b

Front

77. The method that overrides a method in the base class must be prefixed with the ____ keyword. a) virtual c) Sealed b) new d) Overridden

Back

c

Front

62. A constructor is a special type of a _______ in a class. [0.5] a) variable c) method b) instance d) struct

Back

a c

Front

60. Class Book { int num1=1; int num2; public static void Main(){ int num3=3; Console.WriteLine(num1+num2+num3r); } } [2.5] a) 4 c) The code does not compile because static method cannot access nonstatic variables Var1 and var2. b) 0 d) The code does not compile because Var2 is not initialized.

Back

a

Front

98. An interface is a pure abstract class. [0.5] a) True b) False

Back

d

Front

68. Which of the following sentences are true about Constructors? [1.0] a) The constructor can have the same name as that of its class. c) The constructor may or may not have name same as that of the name of its class. b) The constructor can have the same name as one of the methods in the class. d) The constructor must have the same name as that of the name of its class.

Back

c

Front

51. using System; class Test { static void Main() { int @Main; int[] Static= new int[3]; @Main =100*Static[1]; Console.WriteLine(@Main); } } What will be the output of above code? [2.0] a) The code will return an error. c) The code will display 0. b) The code will display 100. d) The code cannot compile.

Back

a

Front

93. Assume that Sub1 and Sub2 are both subclasses of class Super. Given the declarations: Super super = new Super(); Sub1 sub1 = new Sub1(); [2.5] Sub2 sub2 = new Sub2(); Which statement best describes the result of attempting to compile and execute the following statement: super = sub1; a) Compiles and definitely legal at runtime c) Compiles and may be illegal at runtime b) Does not compile

Back

a

Front

88. class Test{ static void Main() { A.F(); B.F(); } } class A { static A() //static constructor { Console.WriteLine("Init A"); } public static void F() { Console.WriteLine("A.F"); } } class B { static B() { Console.WriteLine("Init B"); } public static void F() { Console.WriteLine("B.F"); } } [2.0] a) Init A A.F Init B B.F c) A.F Init B Init A A.F b) Init A Init B A.F B.F d) A.F B.F Init B Init A

Back

a

Front

65. The object invokes the default constructor when no parameters were passed to it. [0.5] a) True b) False

Back

b

Front

74. class A { public static int X = B.Y + 1; } class B { public static int Y = A.X + 1; static void Main() { Console.WriteLine("X = {0}, Y = {1}", A.X, B.Y); } } what will be the output of above code? [1.5] a) X=0, Y=1 c) X=2, Y=1 b) X=1, Y=2 d) The code fails to compile.

Back

a d

Front

53. Value types differ from reference types as___ [2.0] a) data can be stored using value types but not in the reference type. c) variables of the reference types directly contain their data, whereas variables of the value types store references to objects. b) data in the value type variable is easily accessible. d) Variables of the value types directly contain their data, whereas variables of the reference types store references to objects.

Back

c

Front

63. The constructor without parameters is called _________. [0.5] a) main constructor c) default constructor b) zero valued constructor d) non-parameterized constructor

Back

b d

Front

70. Which of the following methods can act as a constructor for the class "Employee" that is used to create an object? [1.0] a) void employee(int enmpno){} c) employee(int empno){} b) Employee (){} d) Employee(int empno){}

Back

a

Front

55. Which statement is true about the following code fragment? 1. int j=2,a=1; 2. switch(j){ 3. case 2: Console.WriteLine("Two");break; 4. case 1+a: Console.WriteLine("Two Two"); break; 5. default: Console.WriteLine(j); 6. } [2.0] a) The code is illegal because of expression at line 4. c) The output would be only the text "Two". b) The acceptable type for variable j as the argument to the switch () construct could be any of byte, short, int or long. d) The output would be only the text "Two" followed by the text "Two Two" followed by the text "2".

Back

d

Front

69. Which of the following methods can act as a constructor for the class [1.0] "Object" that is used to create an object? a) void object(){} c) Object Object(){} b) object(){} d) Object(){}

Back

c

Front

96. The ______ declares a reference type that has abstract member only. [0.5] a) static class c) Interface b) abstract class d) Delegates

Back

a

Front

81. Given these class definitions: class Superclass { } class Subclass1 extends Superclass { } and these objects: Superclass a = new Superclass(); Subclass1 b = new Subclass1(); which of the following explains the result of the statement: b = a; Select the correct statement. [1.5] a) Illegal at compile time c) Definitely legal at runtime b) Legal at compile time but possibly illegal at runtime

Back

a b

Front

44. for(int i=0;i<2;i++){ for(int j=0;j<3;j++){ if(i==j) continue; } Console.WriteLine("i={0} j={1}",i,j); } Which lines would be the part of output? [1.5] a) i=0 j=0 d) i=1 j=0 b) i=0 j=1 e) i=1 j=1 c) i=0 j=2

Back

b

Front

54. What would be the output of the following code fragment? int x=0,y=4,z=5; if(x<2) if(y<4){ Console.WriteLine("One"); } else { Console.WriteLine("Two"); } else if(z>5){ Console.WriteLine("Three"); } else { Console.WriteLine("Four"); } [2.0] a) One c) Three b) Two d) Code will generate an error;

Back

c

Front

58. Which of the following is a legal loop construction? [2.5] (Choose all that apply) a) while(int i<7) { i++; Console.WriteLine("Value of i is {0}",i); } c) int j=0; for(int k=0;j+k!=10;j++,k++) { Console.WriteLine("j= {0} k={1}",j,k); } b) int i=3; while(i){ Console.WriteLine("Value of i is {0}",i); } d) int j=0; do{ Console.WriteLine("Value of i is {0}",,j); if(j==3){continue loop;} }while(j<10);

Back

a

Front

90. Which of the following statements are true with respect to overloading? [2.5] a) Overloading of methods permits a struct, or interface to declare multiple methods with the same name, provided the signatures of the methods are all unique. c) A class can have more than one method called Main with different number of arguments and data types. b) It is possible to overload solely based on return type or solely based on the inclusion or exclusion of the params modifier. d) Unary operators cannot be overloaded.

Back

b

Front

79. What error does the following code generate? //No overload for method 'SuperClass' takes '0' arguments public class SuperClass { SuperClass(string s) { } } public class SubClass : SuperClass { SubClass(string s) { } public static void Main(){ SuperClass s = new SubClass( "The" ); } } [1.5] a) The code will generate no error. c) Incompatible type for '=' can't convert SubClass to SuperClass. b) No constructor matching SuperClass() found in class SuperClass d) Wrong number of arguments in constructor.

Back

b

Front

61. If you run the following program what lines would be included in its output? class A { [2.5] public static void Main () { int i=0; switch (i) { default: System.Console.Write (i); break; case 1: System.Console.Write ("{0}",1); goto default; case 0: System.Console.Write ("{0}",0); goto case 1; } } } a) 100 c) 110 b) 010 d) The program fails to compile.

Back

b

Front

43. Which of the following are valid identifiers? [1.5] a) Void c) @void b) _void d) _var

Back

b

Front

87. 1. public class Test { 2. void show() { 3. System.Console.WriteLine("non-static method in Test"); 4. } 5. } 6. public class Q3:Test { 7. static override void show() { 8. System.Console.WriteLine("Overridden non-static method in [2.0] Q3"); 9. } 10. public static void Main() { a. Q3 a = new Q3(); 11. } } a) Compilation error at line 2. c) No compilation error, but runtime exception at line 3. b) Compilation error at line 7. d) No compilation error, but runtime exception at line 7.

Back

b c e

Front

72. Which of the following is a legal constructor for the class Test. [1.0] a) constructor Test(){ } d) void Test(int a, string s, int f) b) Test() { } e) public Test(int a, int b){} c) Test(int a, int b){}

Back

c

Front

57. char c='a'; switch(c ){ case 'a': Console.WriteLine("A");break; default: Console.WriteLine("Default"); } What will happen if you attempt to compile and run code that includes this snippet? [2.0] a) The code will not compile because the switch statement does not have a legal expression. c) The code will compile and run and the letter "A" will be written to the standard output. b) The code will compile and run but nothing will be return on the standard output. d) The code will compile and run and the word "Default" will be written to the standard output.

Back

b

Front

56. Which statement is true about the following code fragment? 1. int j=2; 2. switch(j){ 3. case 2: Console.WriteLine("Two");break; 4. case 2+1: Console.WriteLine("Three");break; 5. default : Console.WriteLine(j); } [2.0] a) The code is illegal because of expression at line 4. c) The output would be the text "Two" followed by the text "Three". b) The output would be only the text "Two". d) The output would be only the text "Three" followed by the text "Two" followed by the text "2".

Back

d

Front

91. What will happen if you compile/run the following code? 1. public class Q21 { 2. int maxElements; 3. void Q21() { 4. maxElements = 100; 5. System.out.println(maxElements); 6. } 7. Q21(int i) { 8. maxElements = i; 9. System.out.println(maxElements); 10. } [2.5] 11. public static void Main() { 12. Q21 a = new Q21(); 13. Q21 b = new Q21(999); 14. } 15. } a) Prints 100 and 999. c) Compilation error at line 2, variable maxElements was not initialized. b) Prints 999 and 100. d) Compilation error at line 3.

Back

c

Front

80. We have the following organization of classes. class Parent { } class DerivedOne :Parent { } class DerivedTwo :Parent { } Which of the following statements is correct for the following [1.5] expression. Parent p = new Parent(); DerivedOne d1 = new DerivedOne(); DerivedTwo d2 = new DerivedTwo(); p = d1; a) llegal at both compile and runtime, c) Legal at compile and runtime b) Legal at compile time, but fails at runtime,

Back

a

Front

86. Statement I: The sealed modifiers are not permitted in an enum declaration. Statement II: Delegate types are implicitly sealed [2.0] a) Both the statements are true. c) Only statement I is true. b) Both the statements are true. d) Only statement II is true.

Back

d

Front

76. Which of the following methods can be used as a destructor for a class "myClass". a) myclass() { } c) ~myClass(int I){ } b) MyClass() { } d) ~myClass() { }

Back

b

Front

85. Which of the following statements are true with respect to destructors? [2.0] a) Destructors can be invoked explicitly. c) When an instance is destructed, the destructors in an inheritance chain are called in order, from most derived to least derived. b) A class has no other destructors than those that are actually declared in the class. d) Destructors are inherited.

Back

d

Front

67. _______ enables the possibility for a function to be polymorphic when it is overridden in one or more inherited classes. [0.5] a) static c) overridden b) parameterized d) virtual

Back

Section 2

(4 cards)

c

Front

48. What is wrong with the following for statement? for(i=0,,j=0; ++i,j+=i; i<10,++i;) k+=ij+jj; [1.5] a) There should be semicolon between i=0 and j=0. c) It uses more than one loop index. b) It should include more than one statement in the statement block. d) The syntax of for loop is improper.

Back

b d

Front

47. What is wrong with the following for statement? for(i=0;j=0, i<10; ++i,j+=i){ k+=ij+jj; } [1.5] a) It should include more than one statement in the statement block. c) It uses more than one loop index. b) There should be comma between i=0 and j=0. d) There should be a semicolon between j=0 and I<10.

Back

d

Front

49. Array X and Y have integer data types. If these arrays are initialized properly, what is wrong with the following statement? for(int var=0;var<0;++var){ if(x[var]>100) break; if(x[var]<0) continue; x[var+1]=x[var]+y[var]; } [1.5] a) It is illegal to have a break and continue statements within the same for statement. c) The prefix operator is not allowed in the iteration part of a for statement. b) The variable var cannot be declared in the initialization part of a for statement. d) There is nothing wrong with the statement.

Back

b

Front

50. If you ran the following program what lines would be included in its output? int var1,var2; for(var1=0,var2=0;var1+var2<20;++var1,var2+=1) { Console.WriteLine(var1+var2); [1.5] } a) 5 c) 13 b) 8 d) The program cannot compile because the for statement's syntax is incorrect.

Back