Sie sind auf Seite 1von 18

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

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

4. Predict the output of the following code

Public class Test


{
public static void Main(String []args)
{
System.Console.WriteLine(“The program Begins”);
}
}

a) The program will give a compilation error


b) The program will print the output The program Begins
c) The code will compile but will not give any output
d) Error because System.Console.WriteLine should not
be written inside Main()

5. Identify the correct variable from the following


a) 1Mark
b) Student Name
c) Emp_Details
d) D.T.

6. In a C# program which is the first function to be executed


a) Main()
b) Class
c) Function
d) Escapte sequence character

7. The size of the predefined datatype char in C# is


a) 16 bits
b) 8 bits
c) 24 bits
d) 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();


Object.acceptdata();

c) Test object =new Test();


object.acceptdata();

d) Test object=new Test();


Acceptdata().object;

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


a) /
b) //
c) /*
d) ///

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

a) cc
b) csc
c) c++
d) cs

11. In which of the following datatype does the


Console.ReadLine() function accept a value
e) int
f) float
g) bool
h) string

12. The --------------- keyword is to include namespaces


in a program
i) class
j) public
k) using
l) Main()

13. Predict the output of the following


Int x=10;
Int y=3;
Int z=x%y;
System.Console.WriteLine(z);
a) 1
b) 3
c) 9
d) 0

14. Predict the output of the following


Using 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);
}
}
public static void Main(string [] args)
{
test obj=new test();
obj.check();
}
}

a) The program displays Please do not enter zero


b) The program displays the number
c) The program gives a compilation error
d) The program gives a runtime error

15. Predict the output of the following code


Int var;
Var=100;
While(true)
{
Console.WriteLine(“value of var”+var);
Var=var+10;
}

a) The program displays 101


b) The program displays 101 100 times
c) 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


loop
Statement 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 false
o) Statement A is true Statement B is false
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 9
b) The program displays 1 2 3 4 5
c) The program displays 1 10 times
d) 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) protected
c) private
d) public

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 Bye
b) The program will not display anything because Honk() is
private
c) 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 output


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

a) The program displays numbers from 1 to 10


b) The program displays numbers from 10 to 9
c) The program display numbers from 10 to 1
d) 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) private
f) Internal
g) 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
{
result=factorial(n-1)*n
return result;
}
}
public static void Main()
{
number obj=new number();
Console.WriteLine(obj.factorial(4));
}
}

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

24.Predict the output


Using System;
Public class example
{
public static int s;
public void count()
{
s++;
}
public int display()
{
return s;
}
}
class static
{
static int Main()
{
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) 1
b) 1,2,3
c) 1,1,1
d) 3

25. Statement A: static variable retain their values even


after the function to which they belong has been executed
Statement B: Static functions can access static as well as
non static variables

a) A and B are true


b) A is true and B is false
c) A is false and B is true
d) A and B both are false

26. Predict the output


Int 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


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 type
Statement B: Unboxing is a process where value type is
converted to reference type

a) A and B are true


b) A is true and B is false
c) A is false and B is true
d) A and B both are false

28. The subscript number of an array starts from


--------------

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

29 using System;
public class Test
{
int n1,n2,n3;
public Test()
{
n1=0;
n2=0;
n3=0;
Console.WriteLine(“Constructor called”);
}
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 output
b) The program compiles and displays the output 30;
c) The program compiles and displays the output
Constructor called
d) The program compiles and displays the output
Constructor called
30

30 .Predict the output


Using System;
Public class Exam
{
public Exam()
{
display();
}
public void display()
{
Console.WriteLine(“Message 1”);
}
}
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 1
b) Will display
Message1
Message2
Message 1
Message 1

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

31 using System;
public class dest
{
public dest()
{
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 error
b) Constructor Invoked
Constructor Invoked
Constructor Invoked of Derived Class
Destructor Invoked of Derived class
Destructor Invoked
Destructor Invoked
c) constructor Invoked
Constructor Invoked of derived class
Destructor invoked
Destructor 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 classes
Statement 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 false


b) Statement B is true and Statement A is false
c) 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 false


b) Statement B is true and Statement A is false
c) Both are true
d) Both are false

34. Predict the output


using System;
class calculator
{
int n1,n2,n3;
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) 11
c) 16.0
d) 0

35. Statement A: Assignment operators can be overloaded


Statement B: sizeof operator cannot be overloaded

a) Statement A is true Statement B is false


b) Statement B is true Statement A is false
c) Both are true
d) 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 false
b Statement B is true Statement A is false
c) Both are true
d) 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 false


b) Statement B is true and Statement A is false
c) Both are true
d) 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
}
}}
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 correct
d) The program compiles but will not display any output

Das könnte Ihnen auch gefallen