Q-1. WHAT WILL BE THE OUTPUT OF THE FOLLOWING CODE
SNIPPET?
using System;
public class emp
{
public static
int age = 40;
public static
int salary = 25000;
}
public class record :emp
{
new public
static int salary = 50000;
static void
Main(string[] args)
{
Console.WriteLine(emp.age + "
" + emp.salary + "
" + salary);
}
}
|
a) 40, 25000, 50000
b) 40, 25000, 25000
c) 40, 50000, 50000
d) Error
|
Check correct option.
Answer. a)
|
Q-2. WHICH OF THE FOLLOWING KEYWORD, ENABLES TO MODIFY THE
DATA AND BEHAVIOR OF A BASE CLASS BY REPLACING ITS MEMBER WITH A NEW DERIVED
MEMBER?
|
a) overloads
b) overrides
c) new
d) base
|
Check correct option.
Answer. c)
|
Q-3. WHICH OF THE FOLLOWING IS THE CORRECT WAY TO OVERLOAD
“+” OPERATOR?
|
a) public sample operator + ( sample a, sample b)
b) public abstract operator + (sample a, sample b)
c) public static sample operator + (sample a, sample b)
d) All of above
|
Check correct option.
Answer. d)
|
Q-4. WHAT WILL BE THE CORRECT ORDER OF EXECUTION OF
FUNCTION FUNC1(), FUNC2() & FUNC3() IN THE GIVEN CODE SNIPPET?
class baseclass
{
public void
func1() {}
public virtual
void func2() {}
public
virtual void func3() {}
}
class derivedclass :baseclass
{
new public void
func1() {}
public override
void func2() {}
public new void
func3() {}
}
class Program
{
static void
Main(string[] args)
{
baseclass b
= new derivedclass();
b.func1 ();
b.func2 ();
b.func3 ();
}
}
|
a) func1() of derived class get executed
func2() of
derived class get executed
func3() of base
class get executed
b) func1() of base class get executed
func2() of
derived class get executed
func3() of
derived class get executed
c) func1() of derived class get executed
func2() of base
class get executed
func3() of base
class get executed
d) func1() of base class get executed
func2() of
derived class get executed
func3() of base
class get executed
|
Check correct option.
Answer. d)
|
Q-5. WHICH OF THE FOLLOWING STATEMENTS ARE CORRECT FOR C#
LANGUAGE?
|
a) Every derived class does not define its own version of
the virtual method.
b) By default, the access mode for all methods in C# is
virtual.
c) If a derived class, does not define its own version of
the virtual method, then the one present in the base class gets used.
d) All of the above.
|
Check correct option.
Answer. b)
|
Q-6. WHICH OF THE FOLLOWING CODE NEEDS TO BE ADDED FOR THE
OVERLOADED OPERATOR “-” IN C#?
class example
{
int x, y, z;
public example()
{
}
public example(int a ,int b ,int c)
{
x = a;
y = b;
z = c;
}
//Add correct set of code here
public void display()
{
Console.WriteLine(x + " " + y + " " + z);
}
class program
{
static void Main(String[] args)
{
example obj1 = new example(5 ,6 ,8);
example obj2 = new example();
obj2 = - obj1;
obj2.display();
}
}
}
|
a)
public static example operator -(example obj1)
{
example t = new example();
t.x = obj1.x;
t.y = obj1.y;
t.z = -obj1.z;
return t;
}
b)
public static example operator -(example obj1)
{
example t = new
example();
t.x = obj1.x;
t.y = obj1.y;
t.z = obj1.z;
return t;
}
c)
public static example operator -(example obj1)
{
example t = new
example();
t.x = -obj1.x;
t.y = -obj1.y;
t.z = -obj1.z;
return t;
}
d) None of the above
|
Ans: C
|
Q-7. WHICH OF THE FOLLOWING IS THE CORRECT NAME FOR
SELECTING AN APPROPRIATE METHOD FROM A NUMBER OF OVERLOADED METHODS, BY
MATCHING THE ARGUMENTS IN TERMS OF THEIR NUMBER, TYPE, ORDER, AND BINDING AT
COMPILE TIME?
|
a) Late binding
b) Static binding.
c) Static Linking.
d) Compile time polymorphism.
|
Ans:b,c,d
|
Q-8. WHICH OF THE FOLLOWING STATEMENTS ARE CORRECT FOR
RUN-TIME POLYMORPHISM?
|
a) The overridden base method should be virtual,abstract
or override.
b) An abstract method is implicitly a virtual method.
c) An abstract inherited property cannot be overridden in
a derived class.
d) Both override method and virtual method must have same
access level modifier.
|
Answer. a),b),d)
|
Q-9. WHAT WILL BE THE OUTPUT OF THE FOLLOWING CODE
SNIPPET?
using System;
class sample
{
public sample()
{
Console.WriteLine("constructor
1 called");
}
public
sample(int x)
{
int p = 2;
int u;
u = p + x;
Console.WriteLine("constructor 2 called");
}
}
class Program
{
static void
Main(string[] args)
{
sample s =
new sample(4);
sample t =
new sample();
Console.ReadLine();
}
}
|
a) constructor 1 called
constructor 2
called
b) constructor 2 called
constructor 1
called
c) constructor 2 called
constructor 2 called
d) error
|
Check correct option.
Answer. B)
|
Q-10. WHICH OF THE FOLLOWING KEYWORDS IS USED TO REFER
BASE CLASS CONSTRUCTOR TO SUBCLASS CONSTRUCTOR?
|
a) this
b) static
c) base
d) extend
|
Check correct option.
Answer. C)
|
Q-11. WHAT WILL BE THE OUTPUT OF THE FOLLOWING CODE
SNIPPET?
using System;
class sample
{
int i;
public
sample(int x)
{
i = x;
Console.WriteLine("Tech");
}
}
class derived : sample
{
public derived(int x) :base(x)
{
Console.WriteLine("Beamers");
}
}
class Program
{
static void
Main(string[] args)
{
derived k =
new derived(12);
Console.ReadLine();
}
}
|
a) TechBeamers
b) 12 Tech
c) Beamers 12
d) Compile time error
|
Check correct option.
Answer. A)
|
Q-12. WHAT WILL BE THE OUTPUT OF THE FOLLOWING CODE
SNIPPET?
using System;
class sample
{
int i;
public
sample(int num)
{
num = 12;
int j = 12;
int val =
num * j;
Console.WriteLine(val);
}
}
class sample1 : sample
{
public
sample1(int a) :base(a)
{
a = 13;
int b = 13;
Console.WriteLine(a + b);
}
}
class sample2 : sample1
{
public
sample2(int k) :base(k)
{
k = 24;
int o = 6 ;
Console.WriteLine(k /o);
}
}
class Program
{
public static
void Main(string[] args)
{
sample2 t =
new sample2(10);
Console.ReadLine();
}
}
|
a) 4, 26, 144
b) 26, 4, 144
c) 144, 26, 4
d) 0, 0, 0
|
Check correct option.
Answer. C)
|
Q-13. WHAT WILL BE THE OUTPUT OF THE FOLLOWING CODE
SNIPPET?
using System;
class sample
{
static sample()
{
int num = 8;
Console.WriteLine(num);
}
public sample(int a)
{
int val =
10;
Console.WriteLine(val);
}
}
class Program
{
static void
Main(string[] args)
{
sample s =
new sample(100);
Console.ReadLine();
}
}
|
a) 10, 10
b) 0, 10
c) 8, 10
d) 8, 8
|
Check correct option.
Answer. C)
|
Q-14. WHAT WILL BE THE OUTPUT OF THE FOLLOWING CODE
SNIPPET?
using System;
class sample
{
int i;
public sample(int num)
{
num = -25;
int val;
val = num
> 0 ? num : num * -1;
Console.WriteLine(val);
}
}
class sample1 :sample
{
public sample1(int no) :base(no)
{
no = -1000;
Console.WriteLine((no > 0 ? no : no * -1));
}
}
class Program
{
static void
Main(string[] args)
{
sample1 s =
new sample1(6);
Console.ReadLine();
}
}
|
a) 25
1000
b) -25
-1000
c) -25
1000
d) 25
-1000
|
Check correct option.
Answer. A)
|
Q-15. WHICH OF THE FOLLOWING OPTIONS REPRESENTS THE TYPE
OF CLASS WHICH DOES NOT HAVE ITS OWN OBJECTS BUT ACTS AS A BASE CLASS FOR ITS
SUBCLASS?
|
a) Static class
b) Sealed class
c) Abstract class
d) Derived class
|
Check correct option.
Answer. C)
|
Q-16. WHAT WILL BE THE OUTPUT OF THE FOLLOWING CODE
SNIPPET?
using System;
namespace TechBeamers
{
abstract class
baseclass
{
public int i
;
public int j
;
public
abstract void print();
}
class derived:
baseclass
{
public int
j = 5;
public
override void print()
{
this.j
= 3;
Console.WriteLine(i + "
" + j);
}
}
class Program
{
static void Main(string[]
args)
{
derived
obj = new derived();
obj.i =
1;
obj.print();
Console.ReadLine();
}
}
}
|
a) 1, 5
b) 0, 5
c) 1, 0
d) 1, 3
|
Check correct option.
Answer. D)
|
Q-17. WHAT WILL BE THE OUTPUT OF THE FOLLOWING CODE
SNIPPET?
using System;
namespace TechBeamers
{
abstract class
baseclass
{
public int
i;
public
abstract void print();
}
class derived:
baseclass
{
public
int j;
public int
val;
public
override void print()
{
val = i
+ j;
Console.WriteLine(+i + "\n" + +j);
Console.WriteLine("sum is:" +val);
}
}
class Program
{
static void
Main(string[] args)
{
baseclass obj = new derived();
obj.i =
2;
derived
obj1 = new derived();
obj1.j =
10;
obj.print();
Console.ReadLine();
}
}
}
|
a) 2 10
Sum is: 12
b) 0 10
Sum is: 10
c) 2 0
Sum is: 2
d) 0 0
Sum is: 0
|
Check correct option.
Answer. C)
|
Q-18. WHICH OF THE FOLLOWING REPRESENTS A CLASS THAT
INHERITS AN ABSTRACT CLASS BUT IT DOES NOT DEFINE ALL OF ITS FUNCTIONS?
|
a) Abstract
b) A simple class
c) Static class
d) derived class
|
Check correct option.
Answer. A)
|
Q-19. WHAT WILL BE THE OUTPUT OF THE FOLLOWING CODE
SNIPPET?
using System;
namespace TechBeamers
{
public abstract
class sample
{
public int
i = 7;
public
abstract void print();
}
class sample1:
sample
{
public int
j;
public
override void print()
{
Console.WriteLine(i);
Console.WriteLine(j);
}
}
class Program
{
static void
Main(string[] args)
{
sample1
obj = new sample1();
sample
obj1 = new sample1();
obj.j =
1;
obj1.i
= 8;
obj.print();
Console.ReadLine();
}
}
}
|
a) 0, 8
b) 1, 8
c) 1, 7
d) 7, 1
|
Answer D
|
Q-20. WHAT WILL BE THE OUTPUT OF THE FOLLOWING CODE
SNIPPET?
using System;
namespace TechBeamers
{
class sample
{
public int
i;
public void
print()
{
Console.WriteLine(i);
}
}
class sample1:
sample
{
public int
j;
public void
print()
{
Console.WriteLine(j);
}
}
class Program
{
static void
Main(string[] args)
{
sample1
obj = new sample1();
obj.j =
1;
obj.i =
8;
obj.print();
Console.ReadLine();
}
}
}
|
a) 8, 1
b) 8
c) 1
d) 1, 8
|
Answer. C)
|
Comments
Post a Comment