Classes And Objects In C Sharp
Name: _____________________
Date: _____________________
Instructions: Answer all questions. Write your answers clearly in the space provided.
What is the default access modifier for class members in C# if no access modifier is specified?
What is the purpose of the readonly keyword when applied to a field in a class in C#?
In C#, what is the method called automatically when an object is no longer in use and is being destroyed?
What is the process of creating a new class based on an existing class in C# called?
In C#, what is the keyword used to explicitly call a base class constructor from a derived class constructor?
What is the concept in OOP that allows a class to have more than one method with the same name but different parameters in C#?
In C#, which method is automatically called when an object is created to initialize the object's state?
What is the keyword used to create an alias for a data type in C#?
In C#, what is the process of defining a new class within another class called?
What is the access modifier used to declare a class member that is accessible only within its own class in C#?
The process of defining two or more methods within the same class that have same name but different parameters list?
Which of these keywords is used to refer to member of base class from a sub class?
Which of the following functionality is facilitated by inheritance mechanism?
What is the process of defining a method in terms of itself, that is a method that calls itself?
Which keyword is used to declare a base class method while performing overriding of base class methods?
The operator used to access member function of a class?
Which among the following cannot be used as a datatype for an enum in C#.NET?
Which of the following statements about objects in "C#" is correct?
Which of these data types is used by the operating system to manage the Recursion in Csharp?
Select correct differences between '=' and '==' in C#.
The modifier used to hide the base class methods is?
Select the correct statement from the following?
The method called by clients of a class to explicitly release any resources like network, connection, open files etc. When the object is no longer required?
Correct way to define operator method or to perform operator overloading is?
Which of the following statements is correct about constructors in C#.NET?
Which of the following keyword is used to overload user defined types by defining static member functions?
If base class consist of two private integers, one static integer and derived class consist of two static integers and one private integer. What would be the size of derived class object?
Which among the following is the correct statement: Constructors are used to?
What will be the correct statement of the following C# code? enum color:byte
{
yellow = 500,
green = 1000,
pink = 1300
}
Choose the correct statement about enum used in C#.NET?
What will be the output of the following C# expression? int a+= (float) b/= (long)c.
Which of the following statements is correct?
Which statements are correct?
How many values does a function return?
Choose the correct statements about enum used in C#.NET?
Which is the correct way to create an object of the given class abc?
Which of these is not a correct statement?
Wrong statement about inheritance in C# .NET?
What is the return type of constructors?
Which keyword is used for correct implementation of an interface in C#.NET?
Can the method add() be overloaded in the following ways in C#? public int add() { }
public float add(){ }
When does a structure variable get destroyed?
Select wrong statement about destructor in C#?
Which of the following statements correctly define about the implementation of interface?
Choose the correct statement among the following which supports the fact that C# does not allow the creation of empty structures?
Correct method to define + operator is?
What is the correct syntax to declare a method named Display inside a class named Person in C#?
What is the concept in OOP that allows a class to have multiple methods with the same name but different parameters in C#?
What is the access specifier that restricts access to members of a class only within the same class and its derived classes in C#?
What is the method used to destroy an object explicitly in C#?
In C#, what is the process of creating a new class based on an existing class called?
In C#, which keyword is used to prevent a class from being inherited by other classes?
What is the purpose of the static keyword when applied to members of a class in C#?
What is the correct way to access a static member of a class in C#?
What is the process of hiding the implementation details of a class in C#?
In C#, which keyword is used to declare a class member that can only be accessed within its own class and derived classes?
Choose the correct statement about structures as to why they are defined as value types but not reference types?
Does C#.NET support partial implementation of interfaces?
Which statement correctly defines Interfaces in C#.NET?
Which procedure among the following should be used to implement a 'Has a' or a 'Kind of' relationship between two entities?
The process of defining a method in a subclass having same name & type signature as a method in its superclass is known as?
Wrong statement about enum used in C#.NET is?
What is the return type of destructor?
Access specifiers which can be used for an interface are?
A class consists of two interfaces with each interface consisting of three methods. The class had no instance data. Which of the following indicates the correct size of object created from this class?
Choose the correct statements among the following:
In C#, what is the keyword used to create a reference to the current instance of a class?
In C#, what is the method called automatically when an object is no longer referenced and is ready to be removed from memory?
What is the default access modifier for a class in C# if no access modifier is specified?
In C#, which keyword is used to declare a method that can be overridden by a derived class?
In C#, what is the method used to explicitly release resources allocated by an object?
What is the access modifier used to declare a class member that is accessible only within its own class and any class derived from it in C#?
In C#, which keyword is used to explicitly call a base class constructor from a derived class constructor?
In C#, what is the method called automatically when an object is created to initialize the object's state?
What is the concept in OOP that allows a class to have more than one constructor in C#?
What is the keyword used to create an instance of a class in C#?
Which of the following cannot be used to declare an interface correctly?
In an inheritance chain through which of the following, the base class and its components are accessible to the derived class?
Which of the following is used to define the member of a class externally?
Which of these can be overloaded?
Operator used to free the memory when memory is allocated?
Choose the statements which makes interface different from classes?
Which among the following differentiates enum in C#.NET from enum in C language?
Which of the following statements are correct about functions?
Which reference modifier is used to define reference variable?
"A mechanism that binds together code and data in manipulates, and keeps both safe from outside interference and misuse. In short it isolates a particular code and data from all other codes and data. A well-defined interface controls access to that particular code and data."
To override a method in the subclass, the base class method should be defined as?
What is Recursion in CSharp defined as?
Which keyword is used to refer baseclass constructor to subclass constructor?
Which statements among following are correct?
Which of these can be used to fully abstract a class from its implementation?
Select the class visibility modifiers among the following:
Which of the following is the correct way of implementing an interface addition by class maths?
Which of the given modifiers can be used to prevent Method overriding?
Which of the following keyword is used to change data and behavior of a base class by replacing a member of the base class with a new derived member?
Choose the wrong statement about 'INTERFACE' in C#.NET?
Selecting appropriate method out of number of overloaded methods by matching arguments in terms of number, type and order and binding that selected method to object at compile time is called?
If no access modifier for a class is specified, then class accessibility is defined as?
Number of constructors a class can define is?
Correct way to overload +operator?
The data members of a class by default are?
The capability of an object in Csharp to take number of different forms and hence display behaviour as according is known as . . . . . . . .
What is the most specified using class declaration?
Given class sample is inherited by class sample 1. Which are the correct statements about construction of object of class sample?
Arrange the following overloaded operators in increasing order of precedence? %, <<, &, /, +
When we call a constructor method among different given constructors. We match the suitable constructor by matching the name of constructor first, then the number and then the type of parameters to decide which constructor is to be overloaded. The process is also known as?
Which method has the same name as that of its class?
Wrong statement about run time polymorphism is?
Which of the following statements are correct?
Correct statement about constructors in C#.NET is?
Which of the following modifiers is used when an abstract method is redefined by a derived class?
Choose the correct statement among the below mentioned statements.
What is the vector in operator overloading?
The number of levels of inheritance are?
A class member declared protected becomes member of subclass of which type?
Select the wrong statement about 'ref' keyword in C#?
Which of these operators must be used to inherit a class?
The modifier used to define a class which does not have objects of its own but acts as a base class for its subclass is?
Correct statement about constructor overloading in C# is?
Select the correct statement among the given statements?
If a class inheriting an abstract class does not define all of its functions then it is known as?
Select the wrong statements among the following?
Which of the following statements are correct in nature?
Which form of inheritance is not supported directly by C# .NET?
Which of these will happen if the recursive method does not have a base case?
Which operator among the following signifies the destructor operator?
In Inheritance concept, which of the following members of base class are accessible to derived class members?
Choose the wrong statement about structures in C#.NET?
A type of class which does not have its own objects but acts as a base class for its subclass is known as?
What is a class in C#?
Which keyword is used to create an object of a class in C#?
What is an object in C#?
What is the access specifier that allows members of a class to be accessed from any other class in the same assembly in C#?
What is the purpose of a constructor in C#?
Which keyword is used to access members of a class from within the class itself in C#?
In C#, what is the syntax to define a constructor for a class named Car that takes parameters make and model?
What is the keyword used to inherit a class in C#?
In C#, what is the method called automatically when an object of a class is created?
What is the purpose of encapsulation in C#?
Name a method which has the same name as that of class and which is used to destroy objects also called automatically when application is finally on process of being getting terminated.
Which statements are correct about operator overloading?
Choose the wrong statement from the given set of statements?
Operators that can be overloaded are?
Which of the following cannot be used to declare a class as a virtual?
What will be the output of the following C# code? static void Main(string[] args)
{
int []a = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
func(ref a)
Console.ReadLine()
}
static void func(ref int[] x)
{
Console.WriteLine(" numbers are:")
for (int i = 0
i < x.Length
i++)
{
if (x[i] % 2 == 0)
{
x[i] = x[i] + 1
Console.WriteLine(x[i])
}
}
}
What will be the output of the following C# code? enum letters
{
a,
b,
c
}
letters l
l = letters.a
Console.writeline(l)
What will be the output of the following C# code? static void Main(string[] args)
{
int y = 3
y++
if (y <= 5)
{
Console.WriteLine("hi")
Main(args)
}
Console.ReadLine()
}
What will be the output of the following C# code? class maths
{
public int fun(int ii)
{
return(ii > 0 ? ii :ii * -1)
}
public long fun(long ll)
{
return(ll > 0 ? ll :ll * -1)
}
public double fun( double dd)
{
return(dd > 0 ? dd :dd * -1)
}
}
class Program
{
static void Main(string[] args)
{
maths obj = new maths()
int i = -25
int j
long l = -100000l
long m
double d = -12.34
double e
j = obj.fun(i)
m = obj.fun(l)
e = obj.fun(d)
Console.WriteLine(j + " " + m + " " + e)
Console.ReadLine()
}
}
What will be the output of the following C# code? class maths
{
public int fun1(int k)
{
k = 20
return k
}
public Single fun1(float t)
{
t = 3.4f
return t
}
}
class Program
{
static void Main(string[] args)
{
maths obj = new maths()
int i
i = obj.fun1(30)
Console.WriteLine(i)
Single j
j = obj.fun1(2.5f)
Console.WriteLine(j)
Console.ReadLine()
}
}
What will be the output of the following C# code? interface calc
{
void cal(int i)
}
public class maths :calc
{
public int x
public void cal(int i)
{
x = i * i
}
}
class Program
{
public static void Main(string[] args)
{
display arr = new display()
arr.x = 0
arr.cal(2)
Console.WriteLine(arr.x)
Console.ReadLine()
}
}
What will be the output of the following C# code? enum color:int
{
red,
green,
blue = 5,
cyan,
pink = 10,
brown
}
console.writeline((int)color.green)
console.writeline((int)color.brown)
What will be the output of the following C# code? class maths
{
int i
public maths(int ii)
{
ii = -25
int g
g = ii > 0 ? ii : ii * -1
Console.WriteLine(g)
}
}
class maths1 :maths
{
public maths1(int ll) :base(ll)
{
ll = -1000
Console.WriteLine((ll > 0 ? ll : ll * -1))
}
}
class Program
{
static void Main(string[] args)
{
maths1 p = new maths1(6)
Console.ReadLine()
}
}
What will be the output of the following C# code? class maths
{
public static void fun1()
{
Console.WriteLine("method 1 :")
}
public void fun2()
{
fun1()
Console.WriteLine("method 2 :")
}
public void fun2(int k)
{
Console.WriteLine(k)
fun2()
}
}
class Program
{
static void Main(string[] args)
{
maths obj = new maths()
maths.fun1()
obj.fun2(20)
Console.ReadLine()
}
}
What will be the output of the following C# code? static void Main(string[] args)
{
int a = 10 , b = 20
Console.WriteLine("Result before swap is: "+ a +" "+b)
swap(ref a, ref b)
Console.ReadLine()
}
static void swap(ref int i, ref int j)
{
int t
t = i
i = j
j = t
Console.WriteLine("Result after swap is:"+ i +" "+j)
}
What will be the output of the following C# code? class A
{
public int i
private int j
}
class B :A
{
void display()
{
base.j = base.i + 1
Console.WriteLine(base.i + " " + base.j)
}
}
class Program
{
static void Main(string[] args)
{
B obj = new B()
obj.i = 1
obj.j = 2
obj.display()
Console.ReadLine()
}
}
What will be the output of the following C# code? static void Main(string[] args)
{
int a = 5
int s = 0, c = 0
Mul (a, ref s, ref c)
Console.WriteLine(s + "t " +c)
Console.ReadLine()
}
static void Mul (int x, ref int ss, ref int cc)
{
ss = x * x
cc = x * x * x
}
What will be the output of the following C# code? class z
{
public int X
public int Y
public const int c1 = 5
public const int c2 = c1 * 25
public void set(int a, int b)
{
X = a
Y = b
}
}
class Program
{
static void Main(string[] args)
{
z s = new z()
s.set(10, 20)
Console.WriteLine(s.X + " " + s.Y)
Console.WriteLine(z.c1 + " " + z.c2)
Console.ReadLine()
}
}
Which C# statement should be added in function a() of class y to get output "i love csharp"? class x
{
public void a()
{
console.write("bye")
}
}
class y : x
{
public void a()
{
/* add statement here */
console.writeline(" i love csharp ")
}
}
class program
{
static void main(string[] args)
{
y obj = new obj()
obj.a()
}
}
What will be the output of the following C# code? static void Main(string[] args)
{
int x = 8
int b = 16
int C = 64
x /= b /= C /= x
Console.WriteLine(x + " " + b+ " " +C)
Console.ReadLine()
}
What will be the output of the following C# code? interface i1
{
void fun()
}
interface i2
{
void fun()
}
public class maths :i1, i2
{
void i1.fun()
{
Console.WriteLine("i1.fun")
}
void i2.fun()
{
Console.WriteLine("i2.fun")
}
}
class Program
{
static void Main(string[] args)
{
Sample obj = new Sample()
i1 i = (i1) obj
i.fun()
i2 ii = (i2) obj
ii.fun()
}
}
What will be the output of the following C# code? class maths
{
public maths()
{
Console.WriteLine("constructor 1 :")
}
public maths(int x)
{
int p = 2
int u
u = p + x
Console.WriteLine("constructor 2: " +u)
}
}
class Program
{
static void Main(string[] args)
{
maths k = new maths(4)
maths t = new maths()
Console.ReadLine()
}
}
What will be the output of the following C# code? enum colors
{
red,
black,
pink
}
colors s = colors.black
type t
t = c.GetType()
string[] str
str = Enum.GetNames(t)
Console.WriteLine(str[0])
What will be the output of the following C# code? class recursion
{
int fact(int n)
{
int result
if (n == 1)
return 1
result = fact(n - 1) * n
return result
}
}
class Program
{
public static void main(String args[])
{
recursion obj = new recursion()
Console.WriteLine(obj.fact(4))
}
}
What will be the output of the following C# code? static void Main(string[] args)
{
int[] arr = new int[] {1, 2, 3, 4, 5}
fun1(ref arr)
Console.ReadLine()
}
static void fun1(ref int[] array)
{
for (int i = 0
i < array.Length
i++)
{
array[i] = array[i] + 5
Console.WriteLine(array[i] + " ")
}
}
What will be the output of the following C# code? static void Main(string[] args)
{
int a = 5
fun1 (ref a)
Console.WriteLine(a)
Console.ReadLine()
}
static void fun1(ref int a)
{
a = a * a
}
What will be the output of the following C# code? class sample
{
int i
double k
public sample (int ii, double kk)
{
i = ii
k = kk
double j = (i) + (k)
Console.WriteLine(j)
}
~sample()
{
double j = i - k
Console.WriteLine(j)
}
}
class Program
{
static void Main(string[] args)
{
sample s = new sample(8, 2.5)
Console.ReadLine()
}
}
What will be the output of the following C# code? class maths
{
int fact(int n)
{
int result
if (n == 1)
return 1
result = fact(n - 1) * n
return result
}
}
class Output
{
static void main(String args[])
{
maths obj = new maths()
Console.WriteLine(obj.fact(4)*(3))
}
}
What will be the output of the following C# code? namespace ConsoleApplication4
{
class A
{
public int i
public void display()
{
Console.WriteLine(i)
}
}
class B: A
{
public int j
public void display()
{
Console.WriteLine(j)
}
}
class Program
{
static void Main(string[] args)
{
B obj = new B()
obj.j = 1
obj.i = 8
obj.display()
Console.ReadLine()
}
}
}
What will be the output of the following C# code? enum per
{
a,
b,
c,
d,
}
per.a = 10
Console.writeline(per.b)
What will be the output of the following C# code? class sample
{
public sample()
{
Console.WriteLine("THIS IS BASE CLASS constructor")
}
}
public class sample1 : sample
{
}
class Program
{
static void Main(string[] args)
{
sample1 obj = new sample1()
Console.ReadLine()
}
}
What will be the output of the following C# code? class maths
{
public int x
public double y
public int add(int a, int b)
{
x = a + b
return x
}
public int add(double c, double d)
{
y = c + d
return (int)y
}
public maths()
{
this.x = 0
this.y = 0
}
}
class Program
{
static void Main(string[] args)
{
maths obj = new maths()
int a = 4
double b = 3.5
obj.add(a, a)
obj.add(b, b)
Console.WriteLine(obj.x + " " + obj.y)
Console.ReadLine()
}
}
What will be the Correct statement in the following C# code? interface a1
{
void f1()
int f2()
}
class a :a1
{
void f1()
{
}
int a1.f2()
{
}
}
What will be the output of the following C# code snippet? class maths
{
public int fact(int n)
{
int result
if (n == 2)
return 1
result = fact(n - 1) * n
return result
}
}
class Program
{
static void Main(string[] args)
{
maths obj = new maths()
Console.WriteLine(obj.fact(4))
Console.ReadLine()
}
}
What will be the Correct statement in the following C# code? class sample
{
protected int index
public sample()
{
index = 0
}
}
class sample 1: sample
{
public void add()
{
index += 1
}
}
class Program
{
static void Main(string[] args)
{
sample 1 z = new sample 1()
z . add()
}
}
What will be the output of the following C# code? class A
{
public int i
public void display()
{
Console.WriteLine(i)
}
}
class B: A
{
public int j
public void display()
{
Console.WriteLine(j)
}
}
class Program
{
static void Main(string[] args)
{
B obj = new B()
obj.i = 1
obj.j = 2
obj.display()
Console.ReadLine()
}
}
What will be the correct statement in the following C# code? class trial
{
int i
float d
}
struct sample
{
private int x
private Single y
private trial z
}
sample s = new sample()
What will be the output of the following C# code? namespace ConsoleApplication4
{
abstract class A
{
public int i
public int j
public abstract void display()
}
class B: A
{
public int j = 5
public override void display()
{
this.j = 3
Console.WriteLine(i + " " + j)
}
}
class Program
{
static void Main(string[] args)
{
B obj = new B()
obj.i = 1
obj.display()
Console.ReadLine()
}
}
}
What will be the correct statement in the following C# code? struct book
{
private String name
private int pages
private Single price
}
book b = new book()
What will be the output of the following C# code? static void Main(string[] args)
{
int x = 8
int b = 16
int C = 64
x /= b /= C
Console.WriteLine(x + " " + b+ " " +C)
Console.ReadLine()
}
What will be the output of the following C# code? static void Main(string[] args)
{
int i = 10
double d = 35.78
fun(i)
fun(d)
Console.ReadLine()
}
static void fun(double d)
{
Console.WriteLine(d)
}
What will be the Correct statement in the following C# code? class baseclass
{
int a
public baseclass(int a1)
{
a = a1
console.writeline(" a ")
}
class derivedclass : baseclass
{
public derivedclass (int a1) : base(a1)
{
console.writeline(" b ")
}
}
class program
{
static void main(string[] args)
{
derivedclass d = new derivedclass(20)
}
}
}
What will be the output of the following C# code? class A
{
public int i
protected int j
}
class B : A
{
public int j
public void display()
{
base.j = 3
Console.WriteLine(i + " " + j)
}
}
class Program
{
static void Main(string[] args)
{
B obj = new B()
obj.i = 1
obj.j = 2
obj.display()
Console.ReadLine()
}
}
What will be the output of the following C# code? class overload
{
public int x
int y
public int add(int a)
{
x = a + 1
return x
}
public int add(int a, int b)
{
x = a + 2
return x
}
}
class Program
{
static void Main(string[] args)
{
overload obj = new overload()
overload obj1 = new overload()
int a = 0
obj.add(6)
obj1.add(6, 2)
Console.WriteLine(obj.x)
Console.WriteLine(obj1.x)
Console.ReadLine()
}
}
What will be the output of the following C# code? class maths
{
public int length
public int breadth
public maths(int x)
{
length = x + 1
}
public maths(int x, int y)
{
length = x + 2
}
}
class Program
{
static void Main(string[] args)
{
maths m = new maths(6)
maths k = new maths(6, 2)
Console.WriteLine(m.length)
Console.WriteLine(k.length)
Console.ReadLine()
}
}
What will be the output of the following C# code? public class sample
{
public static int x = 100
public static int y = 150
}
public class newspaper :sample
{
new public static int x = 1000
static void Main(string[] args)
{
console.writeline(sample.x + " " + sample.y + " " + x)
}
}
What will be the output of the following C# code? class box
{
public int volume
int width
int height
int length
public box ( int w, int h, int l)
{
width = w
height = h
length = l
}
public ~box()
{
volume = width * length * height
}
}
class Program
{
static void Main(string[] args)
{
box b = new box(4, 5, 9)
Console.WriteLine(b.volume)
Console.ReadLine()
}
}
What will be the output of the following C# code? using System
public class BaseClass
{
public BaseClass()
{
Console.WriteLine("I am a base class")
}
}
public class ChildClass : BaseClass
{
public ChildClass()
{
Console.WriteLine ("I am a child class")
}
static void Main()
{
ChildClass CC = new ChildClass()
}
}
What will be the output of the following C# code? class a
{
public void fun()
{
Console.WriteLine("base method")
}
}
class b: a
{
public new void fun()
{
Console.WriteLine(" derived method ")
}
}
class Program
{
static void Main(string[] args)
{
b k = new b()
k.fun()
Console.ReadLine()
}
}
What will be the output of the following C# code? class sample
{
public int i
void display()
{
Console.WriteLine(i)
}
}
class sample1 : sample
{
public int j
public void display()
{
Console.WriteLine(j)
}
}
class Program
{
static void Main(string[] args)
{
sample1 obj = new sample1()
obj.i = 1
obj.j = 2
obj.display()
Console.ReadLine()
}
}
What will be the output of the following C# code? class abc
{
public static void a()
{
console.writeline("first method")
}
public void b()
{
a()
console.writeline("second method")
}
public void b(int i)
{
console.writeline(i)
b()
}
}
class program
{
static void main()
{
abc k = new abc()
abc.a()
k.b(20)
}
}
What will be the output of the following C# code? class Program
{
static void Main(string[] args)
{
Console.WriteLine( vol(10))
Console.WriteLine( vol(2.5f, 5))
Console.WriteLine( vol( 5l, 4, 5))
Console.ReadLine()
}
static int vol(int x)
{
return(x * x * x)
}
static float vol(float r, int h)
{
return(3.14f * r * r * h)
}
static long vol(long l, int b, int h)
{
return(l * b * h)
}
}
What will be the output of the following C# code? class maths
{
public int fun(int k, int y, int n)
{
Console.WriteLine(k + " " + y + " " + n)
return (k)
}
public int fun1(int t,float z)
{
Console.WriteLine(t + " " + z)
return t
}
}
class Program
{
static void Main(string[] args)
{
maths obj = new maths()
int b = 90
int c = 100
int d
float l
int i = obj.fun(b, c, 12)
int j = (obj.fun1(12, 14.78f))
Console.ReadLine()
}
}
What will be the output of the following C# code? class sample
{
public int i
public int[] arr = new int[10]
public void fun(int i, int val)
{
arr[i] = val
}
}
class Program
{
static void Main(string[] args)
{
sample s = new sample()
s.i = 10
sample.fun(1, 5)
s.fun(1, 5)
Console.ReadLine()
}
}
The correct way to define a variable of type struct abc in the following C# code? struct abc
{
public string name
protected internal int age
private Single sal
}
What will be the output of the following C# code? static void Main(string[] args)
{
int X = 0
if (Convert.ToBoolean(X = 0))
Console.WriteLine("It is zero")
else
Console.WriteLine("It is not zero")
Console.ReadLine()
}
What will be the output of the following C# code? class maths
{
int i
public maths(int x)
{
i = x
Console.WriteLine(" hello: ")
}
}
class maths1 : maths
{
public maths1(int x) :base(x)
{
Console.WriteLine("bye")
}
}
class Program
{
static void Main(string[] args)
{
maths1 k = new maths1(12)
Console.ReadLine()
}
}
Calculate the number of bytes a structure variable s occupies in the memory if it is defined as follows. class abc
{
int i
Decimal d
}
struct sample
{
private int x
private Single y
private trial z
}
sample s = new sample()
What will be the output of the following C# code? class maths
{
int i
public maths(int ii)
{
ii = 12
int j = 12
int r = ii * j
Console.WriteLine(r)
}
}
class maths1 : maths
{
public maths1(int u) :base(u)
{
u = 13
int h = 13
Console.WriteLine(u + h)
}
}
class maths2 : maths1
{
public maths2(int k) :base(k)
{
k = 24
int o = 6
Console.WriteLine(k /o)
}
}
class Program
{
static void Main(string[] args)
{
maths2 t = new maths2(10)
Console.ReadLine()
}
}
What will be the output of the following C# code? class test
{
public void print()
{
Console.WriteLine("Csharp:")
}
}
class Program
{
static void Main(string[] args)
{
test t
t.print()
Console.ReadLine()
}
}
Which return statement correctly returns the output?
What will be the output of the following C# code? namespace ConsoleApplication4
{
abstract class A
{
int i
public abstract void display()
}
class B: A
{
public int j
public override void display()
{
Console.WriteLine(j)
}
}
class Program
{
static void Main(string[] args)
{
B obj = new B()
obj.j = 2
obj.display()
Console.ReadLine()
}
}
}
What will be the output of the following C# code? class maths
{
static maths()
{
int s = 8
Console.WriteLine(s)
}
public maths(int f)
{
int h = 10
Console.WriteLine(h)
}
}
class Program
{
static void Main(string[] args)
{
maths p = new maths(0)
Console.ReadLine()
}
}
What will be the output of the following C# code? enum days:int
{
sunday = -3,
monday,
tuesday
}
Console.WriteLine((int)days.sunday)
Console.WriteLine((int)days.monday)
Console.WriteLine((int)days.tuesday)
What will be the output of the following C# code? static void Main(string[] args)
{
int X = 6,Y = 2
X *= X / Y
Console.WriteLine(X)
Console.ReadLine()
}
What does the following C# code signify? class a
{
}
class b : a
{
variable declaration
method declaration
}
What will be the Correct statement in the following C# code? interface abc
{
String FirstName
{
get
set
}
String LastName
{
get
set
}
void print()
void stock()
int fun()
}
What will be the output of the following C# code? interface i1
{
void f1()
}
interface i2 :i1
{
void f2()
}
public class maths :i2
{
public void f2()
{
Console.WriteLine("fun2")
}
public void f1()
{
Console.WriteLine("fun1")
}
}
class Program
{
static Void Main()
{
maths m = new maths()
m.f1()
m.f2()
}
}
What will be the output of the following C# code? namespace ConsoleApplication4
{
abstract class A
{
public int i
public abstract void display()
}
class B: A
{
public int j
public int sum
public override void display()
{
sum = i + j
Console.WriteLine(+i + "
" + +j)
Console.WriteLine("sum is:" +sum)
}
}
class Program
{
static void Main(string[] args)
{
A obj = new B()
obj.i = 2
B obj1 = new B()
obj1.j = 10
obj.display()
Console.ReadLine()
}
}
}
What will be the output of the following C# code? class maths
{
public int length
public int breadth
public maths(int x, int y)
{
length = x
breadth = y
Console.WriteLine(x + y)
}
public maths(double x, int y)
{
length = (int)x
breadth = y
Console.WriteLine(x * y)
}
}
class Program
{
static void Main(string[] args)
{
maths m = new maths(20, 40)
maths k = new maths(12.0, 12)
Console.ReadLine()
}
}
What will be the output of the following C# code? static void Main(string[] args)
{
int x = 4 ,b = 2
x -= b/= x * b
Console.WriteLine(x + " " + b)
Console.ReadLine()
}
What will be the output of the following C# code? class z
{
public string name1
public string address
public void show()
{
Console.WriteLine("{0} is in city{1}", name1, " ", address)
}
}
class Program
{
static void Main(string[] args)
{
z n = new z()
n.name1 = "harsh"
n.address = "new delhi"
n.show()
Console.ReadLine()
}
}
Which of the following is the correct result for the given statement in the C#.NET statement given below? p = q struct employee
{
private int employee id
private string city
}
employee q = new employee()
employee p
p = q
Select the statement which should be added to the current C# code to get the output as 10 20? class baseclass
{
protected int a = 20
}
class derived : baseclass
{
int a = 10
public void math()
{
/* add code here */
}
}
What will be the output of the following C# code? interface calc
{
void cal(int i)
}
class displayA :calc
{
public int x
public void cal(int i)
{
x = i * i
}
}
class displayB :calc
{
public int x
public void cal(int i)
{
x = i / i
}
}
class Program
{
public static void Main(string[] args)
{
displayA arr1 = new displayA()
displayB arr2 = new displayB()
arr1.x = 0
arr2.x = 0
arr1.cal(2)
arr2.cal(2)
Console.WriteLine(arr1.x + " " + arr2.x)
Console.ReadLine()
}
}
What will be the output of the following C# code? class box
{
public int volume
int width
int height
int length
public box ( int w, int h, int l)
{
this.width = w
this.height = h
this.length = l
}
~ box()
{
volume = this.width * this.length * this.height
console.writeline(volume)
}
}
class Program
{
public static void Main(string[] args)
{
box b = new box(4, 5, 9)
Console.ReadLine()
}
}
Correct way to define object of sample class in which C# code will work correctly is: class abc
{
int i
float k
public abc(int ii, float kk)
{
i = ii
k = kk
}
}
What will be the output of the following C# code? class maths
{
public int fun(int k, int y)
{
return k + y
}
public int fun1(int t, float z)
{
return (t+(int)z)
}
}
class Program
{
static void Main(string[] args)
{
maths obj = new maths()
int i
int b = 90
int c = 100
int d = 12
float l = 14.78f
i = obj.fun(b, c)
Console.WriteLine(i)
int j = (obj.fun1(d, l))
Console.WriteLine(j)
Console.ReadLine()
}
}
What will be the output of the following C# code? static void Main(string[] args)
{
int i = 5
int j = 6
add(ref i)
add(6)
Console.WriteLine(i)
Console.ReadLine()
}
static void add(ref int x)
{
x = x * x
}
static void add(int x)
{
Console.WriteLine(x * x * x)
}
What will be the output of the following C# code? class sample
{
public int i
public int j
public void fun(int i, int j)
{
this.i = i
this.j = j
}
}
class Program
{
static void Main(string[] args)
{
sample s = new sample()
s.i = 1
s.j = 2
s.fun(s.i, s.j)
Console.WriteLine(s.i + " " + s.j)
Console.ReadLine()
}
}
What will be size of the object created depicted by C# code snippet? class baseclass
{
private int a
protected int b
public int c
}
class derived : baseclass
{
private int x
protected int y
public int z
}
class Program
{
static Void Main(string[] args)
{
derived a = new derived()
}
}
When a function fun() is to receive an int, a single & a double and it is to return a decimal, then the correct way of defining this C# function is?
Which of the following is the correct way to settle down values into the structure variable 'e' defined in the following C# code snippet? struct emp
{
public String name
public int age
public Single sal
}
emp e = new emp()
What will be the output of the following C# code snippet? class maths
{
int fact(int n)
{
int result
if (n == 1)
return 1
result = fact(n - 1) * n
return result
}
}
class Output
{
static void main(String args[])
{
maths obj = new maths()
Console.WriteLine(obj.fact(4)*obj.fact(2))
}
}
What will be the output of the following C# code? static void Main(string[] args)
{
Mul()
m()
Console.ReadLine()
}
static void Mul()
{
Console.WriteLine("4")
}
static void m()
{
Console.WriteLine("3")
Mul()
}
What will be the output of the following C# code? {
struct abc
{
int i
}
class Program
{
static void Main(string[] args)
{
abc x = new abc()
abc z
x.i = 10
z = x
z.i = 15
console.Writeline(x.i + " " + y.i)
}
}
}
What will be the output of the following C# code snippet? class maths
{
public int fact(int n)
{
int result
result = fact(n - 1) * n
return result
}
}
class Program
{
static void Main(string[] args)
{
maths obj = new maths()
Console.WriteLine(obj.fact(4))
Console.ReadLine()
}
}
What will be the output of the following C# code? namespace ConsoleApplication4
{
public abstract class A
{
public int i = 7
public abstract void display()
}
class B: A
{
public int j
public override void display()
{
Console.WriteLine(i)
Console.WriteLine(j)
}
}
class Program
{
static void Main(string[] args)
{
B obj = new B()
A obj1 = new B()
obj.j = 1
obj1.i = 8
obj.display()
Console.ReadLine()
}
}
}
What does the following C# code imply? csharp abc
abc = new charp()
What will be the output of the following C# code? class A
{
public virtual void display()
{
Console.WriteLine("A")
}
}
class B: A
{
public override void display()
{
Console.WriteLine(" B ")
}
}
class Program
{
static void Main(string[] args)
{
A obj1 = new A()
B obj2 = new B()
A r
r = obj1
r.display()
r = obj2
r.display()
Console.ReadLine()
}
}
Correct way of declaration of object of the following class is? class name
Select the sequence of execution of function f1(), f2() & f3() in C# .NET CODE? class base
{
public void f1() {}
public virtual void f2() {}
public virtual void f3() {}
}
class derived :base
{
new public void f1() {}
public override void f2() {}
public new void f3() {}
}
class Program
{
static void Main(string[] args)
{
baseclass b = new derived()
b.f1 ()
b.f2 ()
b.f3 ()
}
}
The following C# code is run on single level of inheritance. What will be the Correct statement in the following C# code? class sample
{
int i = 10
int j = 20
public void display()
{
Console.WriteLine("base method ")
}
}
class sample1 : sample
{
public int s = 30
}
class Program
{
static void Main(string[] args)
{
sample1 obj = new sample1()
Console.WriteLine("{0}, {1}, {2}", obj.i, obj.j, obj.s)
obj.display()
Console.ReadLine()
}
}
What will be the output of the following C# code? public static void Main(string[] args)
{
p()
void p()
{
Console.WriteLine("hi")
}
}
What will be the output of the following C# code? static void Main(string[] args)
{
m()
Console.ReadLine()
}
static void m()
{
Console.WriteLine("HI")
m()
}
What will be the Correct statement of the following C# code? public class maths
{
public int x
public virtual void a()
{
}
}
public class subject : maths
{
new public void a()
{
}
}
What will be the output of the following C# code? {
struct abc
{
public int i
}
class Program
{
static void Main(string[] args)
{
sample a = new sample()
a.i = 10
fun(ref a)
Console.WriteLine(a.i)
}
public static voidn fun(ref sample x)
{
x.i = 20
Console.WriteLine(x.i)
}
}
}
What will be the output of the following C# code? class maths
{
int fact(int n)
{
int result
if (n == 1)
return 1
result = fact(n - 1) * n
return result
}
}
class Output
{
static void main(String args[])
{
maths obj = new maths()
Console.WriteLine(obj.fact(1))
}
}
What will be the Correct statement in the following C# code? interface a1
{
void f1()
void f2()
}
class a :a1
{
private int i
void a1.f1()
{
}
}