23
C Sharp Mock Test 1. Statement A: An object is a combination of messages and data Satement B: The state of an object is indicated by a set of attributes and their values a) Statement A is true Statement B is false b) Statement B is true Statement A is false c) Both are false d) Both are true 2. The description of a problem is identified in ---------------------- stage a) Analysis phase b) Design Phase c) Implementation phase 3. Statement A: A compiler is a special program that processes the statements written in a particular language and converts them into machine language Statement B: A class is an instance of an object

C Sharp Mock Test {Qtz}

Embed Size (px)

Citation preview

Page 1: C Sharp Mock Test {Qtz}

C Sharp Mock Test

1. Statement A: An object is a combination of messages and dataSatement B: The state of an object is indicated by a set of attributes and their values

a) Statement A is true Statement B is falseb) Statement B is true Statement A is falsec) Both are falsed) Both are true

2. The description of a problem is identified in ---------------------- stage

a) Analysis phase b) Design Phasec) Implementation phase

3. Statement A: A compiler is a special program that processes the statements written in a particular language and converts them into machine languageStatement B: A class is an instance of an object

a) Statement A is true Statement B is false b) Statement B is true Statement A is falsec) Both are falsed) Both are true

4. Predict the output of the following code

Public class Test{public static void Main(String []args){

System.Console.WriteLine(“The program Begins”);

Page 2: C Sharp Mock Test {Qtz}

}}

a) The program will give a compilation errorb) The program will print the output The program Beginsc) The code will compile but will not give any outputd) Error because System.Console.WriteLine should not

be written inside Main()

5. Identify the correct variable from the followinga) 1Markb) Student Namec) Emp_Details d) D.T.

6. In a C# program which is the first function to be executeda) Main() b) Classc) Functiond) Escapte sequence character

7. The size of the predefined datatype char in C# isa) 16 bits b) 8 bits c) 24 bitsd) 64 bits

8. In a C# sharp program if the name of the class is Test and name of the method is acceptdata. Identify the correct way to declare an object and call the function acceptdata

a) object Test;

object.acceptdata();

b) Test object=new Test();

Page 3: C Sharp Mock Test {Qtz}

Object.acceptdata();

c) Test object =new Test(); object.acceptdata();

d) Test object=new Test();

Acceptdata().object;

9 which of the following is used to give a single line

commenta) /b) // c) /*d) ///

10. The -------- compiler is used for C#

a) ccb) csc c) c++d) cs

11. In which of the following datatype does the Console.ReadLine() function accept a value

e) intf) floatg) boolh) string

Page 4: C Sharp Mock Test {Qtz}

12. The --------------- keyword is to include namespaces in a program

i) classj) publick) using l) Main()

13. Predict the output of the followingInt x=10;Int y=3;Int z=x%y;

System.Console.WriteLine(z);a) 1 b) 3c) 9d) 0

14. Predict the output of the followingUsing System;

class test{

public void check(){int x;x=Convert.ToInt32(Console.ReadLine());if(x=0){Console.WriteLine("Please do not enter zero");}else{Console.WriteLine(x);}}

Page 5: C Sharp Mock Test {Qtz}

public static void Main(string [] args){test obj=new test();obj.check();}

}

a) The program displays Please do not enter zerob) The program displays the numberc) The program gives a compilation error d) The program gives a runtime error

15. Predict the output of the following codeInt var;Var=100;While(true){Console.WriteLine(“value of var”+var);Var=var+10;}

a) The program displays 101b) The program displays 101 100 timesc) The program will run for indefinite number of times d) The program gives compilation error

16. Statement A: Break Statement is used to exit from a loopStatement B: Continue statement is used to skip all the subsequent instructions and take the control back to the loop

m) Both statements are true n) Both statements are falseo) Statement A is true Statement B is false

Page 6: C Sharp Mock Test {Qtz}

p) Statement B is true Statement A is false

17. class test{

public void check(){int x;x=1;while(x<10){Console.WriteLine(x);x++;if(x==6)break;}}public static void Main(string [] args){test obj=new test();obj.check();}

} a) The program displays numbers from 1 to 9b) The program displays 1 2 3 4 5 c) The program displays 1 10 timesd) The program displays 1 to 10

18.Which of the following access specifier is used to access member variables and member functions within the application

a) Internal b) protectedc) privated) public

Page 7: C Sharp Mock Test {Qtz}

19. predict the output of the following code using System; class car{

private void Honk(){Console.WriteLine(“Good Bye”);}

}class Display{

public static void Main(String []args){ car obj=new car(); obj.Honk();}

}a) The program displays Good Byeb) The program will not display anything because Honk() is

privatec) The program will give compilation error in line

obj.Honk() because private members cannot be accessed outside class

d) Main Method should be given in class Display

20Predict the outputClass test{

int I;for(i=10;i>=0;i--){System.Console.WriteLine(i);}

}

Page 8: C Sharp Mock Test {Qtz}

a) The program displays numbers from 1 to 10b) The program displays numbers from 10 to 9c) The program display numbers from 10 to 1d) The program displays numbers from 10 to 0

21.Which of the following operators can be used to evaluate an expression to true only if both the conditions are true

a) && b) ||c) >=d) !=

22.Which of the following access specifier is used to hide member variables and member functions to be accessed from other class objects and functions,except the child class within the application

e) privatef) Internalg) Protected internal h) Public

23 predict the output

using System;class number{public int factorial(int n){int result;if(n==1)return 1;else{

Page 9: C Sharp Mock Test {Qtz}

result=factorial(n-1)*nreturn result;}}public static void Main(){number obj=new number();Console.WriteLine(obj.factorial(4));}}

a) 4b) 16 c) 24d) 120

24.Predict the outputUsing System;Public class example{public static int s;public void count(){s++;}public int display(){return s;}}class static{static int Main(){

Page 10: C Sharp Mock Test {Qtz}

example e=new example();example e1=new example();e.count();e.count();e.count();Console.WriteLine(“The value is {0}”,e1.display());Console.ReadLine();}}

a) 1b) 1,2,3c) 1,1,1d) 3

25. Statement A: static variable retain their values even after the function to which they belong has been executedStatement B: Static functions can access static as well as non static variables

a) A and B are trueb) A is true and B is false c) A is false and B is trued) A and B both are false

26. Predict the outputInt score[] ;Score=new int[3] {1,2,3};System.Console.WriteLine(score[0]);System.Console.WriteLine(score[1]);System.Console.WriteLine(score[2]);

a) will print 1,2,3

Page 11: C Sharp Mock Test {Qtz}

b) The program will give compilation error because the array is not declared correctly

c) The program will give compilation error because the print statement is not given correctly

d) The program will compile but will not give any output

27. Statement A: Boxing is a process where reference type is converted to value typeStatement B: Unboxing is a process where value type is converted to reference type

a) A and B are trueb) A is true and B is false c) A is false and B is trued) A and B both are false

28. The subscript number of an array starts from --------------

a) 0 b) -1c) 1d) 2

29 using System;public class Test{

int n1,n2,n3;public Test(){n1=0;n2=0;n3=0;Console.WriteLine(“Constructor called”);}

Page 12: C Sharp Mock Test {Qtz}

public Test(int x,int y){n1=x;n2=y;n3=x+y;Console.WriteLine(n3);}

public static void Main(){Test obj =new Test();Test obj2=new Test(10,20);}}a) The program compiles but does not give any outputb) The program compiles and displays the output 30;c) The program compiles and displays the output

Constructor calledd) The program compiles and displays the output Constructor called 30

30 .Predict the outputUsing System;Public class Exam{public Exam(){display();}public void display(){Console.WriteLine(“Message 1”);}}

Page 13: C Sharp Mock Test {Qtz}

public MT1 : Exam{public MT1(){display();Console.WriteLine(“Message2”);}public static void Main(){Exam obj=new Exam();MT1 obj2=new MT1();}}

a) Will display Message 1b) Will display

Message1Message2Message 1Message 1

c) will display Message 2

d) will display Message 1Message 1Message 1Message 2

31 using System;public class dest{

public dest()

Page 14: C Sharp Mock Test {Qtz}

{Console.WriteLine("Constructor Invoked");}~dest(){Console.WriteLine("Destructor Invoked");}

}class derived:dest{

public derived(){Console.WriteLine("Constructor Invoked of derived

class");}~derived(){Console.WriteLine("Destructor Invoked of derived

class");}

}class test{

public static void Main(){dest obj=new dest();derived obj2=new derived();}

}

a) Compilation errorb) Constructor Invoked

Constructor InvokedConstructor Invoked of Derived ClassDestructor Invoked of Derived class

Page 15: C Sharp Mock Test {Qtz}

Destructor InvokedDestructor Invoked

c) constructor InvokedConstructor Invoked of derived classDestructor invokedDestructor invoked

d) Constructor Invoked Destructor Invoked

32. Statement A: Finalize() destructor is a special method that is called from the class to which it belongs or from derived classesStatement B: The Finalize() destructor is called after the last reference to an object is released from memory

a) Statement A is true and Statement B is falseb) Statement B is true and Statement A is falsec) Both are true d) Both are false

33. Statement A: In dynamic polymorphism the decision about function execution is made at run time Statement B: Abstract classes are used to implement dynamic polymorphism

a) Statement A is true and Statement B is falseb) Statement B is true and Statement A is falsec) Both are true d) Both are false

34. Predict the output using System; class calculator {

int n1,n2,n3;

Page 16: C Sharp Mock Test {Qtz}

public calculator() {

n1=0;n2=0;n3=0;

}public void add(int x,int y){n1=x;n2=y;n3=x+y;Console.WriteLine(n3);}public void add(float x,float y){n1=x;n2=y;n3=x+y;}public static void Main(){calculator obj=new calculator();obj.add(5,6);obj.add(10.5f,5.5f);}

}

a) 11,16.0 b) 11c) 16.0d) 0

35. Statement A: Assignment operators can be overloaded Statement B: sizeof operator cannot be overloaded

Page 17: C Sharp Mock Test {Qtz}

a) Statement A is true Statement B is false b) Statement B is true Statement A is false c) Both are trued) Both are false

36. Statement A: Abstract classes contain abstract methods which can be implemented by the derived class Statement B: An instance of abstract class can be created

a) Statement A is true Statement B is falseb Statement B is true Statement A is falsec) Both are trued) Both are false

37. Statement A: Interface defines properties, method, events and variables Statement B: All the members in an interface are by default public

a) Statement A is true and Statement B is falseb) Statement B is true and Statement A is false c) Both are trued) Both are false

38. Predict the output using System; interface MyInterface{

public void calculate();public void display();

}class Student:MyInterface{

public void calculate(){// doing some calculation

Page 18: C Sharp Mock Test {Qtz}

}}}

a) The program compiles b) The program will not compile because class is not

implementing the method display c) The program will not compile because the syntax for

declaring the interface is not correctd) The program compiles but will not display any output