Technical Test Paper 1
(Constructor ,Inheritance,Interface)
Q.1.Which of the following should be used to implements a "Has a" relationship between two entities?
A. Polymorphism B.Templates C.Containrship D.Inheritance
Ans:-A.Polymorphism (means One message can pass by object )
Q.2.Which of the following is correct the C#.NET snippet given below?
namespace ConsoleApplication
{
class BaseClass
{
public void fun ( )
{
Console.WriteLine ("Hi"+" ");
}
public void fun (int i)
{
Console.WriteLine("Hello"+" ");
}
}
class Derived: Baseclass
{
public void fun ( )
{
Console.WriteLine("Bye"+" ");
}
}
class MyProgram
{
static void Main(String[ ] args)
{
Derived d;
d= new Derived ( );
d.fun ( );
d.fun(77);
}
}
}
Ans:-The Program Gives the Output as :Bye Hello
Q.3. Which of the following are reuse mechanisms available in C#.NET?
1.Inheritance 2.Encapsulation 3.Templates 4.Containership 5.Polymorphism
A) 1 and 4 B) 1 and 3 C) 2 and 4 D) 3 and 5
Ans:- A) Inheritance and Polymorphism
namespace ConsoleApplication
{
class BaseClass
{
public void fun ( )
{
Console.WriteLine ("Hi"+" ");
}
public void fun (int i)
{
Console.WriteLine("Hello"+" ");
}
}
class Derived: Baseclass
{
public void fun ( )
{
Console.WriteLine("Bye"+" ");
}
}
class MyProgram
{
static void Main(String[ ] args)
{
Derived d;
d= new Derived ( );
d.fun ( );
d.fun(77);
}
}
}
Ans:-The Program Gives the Output as :Bye Hello
Q.3. Which of the following are reuse mechanisms available in C#.NET?
1.Inheritance 2.Encapsulation 3.Templates 4.Containership 5.Polymorphism
A) 1 and 4 B) 1 and 3 C) 2 and 4 D) 3 and 5
Ans:- A) Inheritance and Polymorphism
Q.4.Which of the following statements are correct about Inheritance in C#.NET?
1. A derived class object contains all the base class data.
2.Inheritance cannot suppress the base class functionality.
3.A derived class may not be able to access all the base class data.
4.Inheritance cannot extend the base class functionality.
5.In inheritance chain construction of object happens from base towards derived.
A)1,2,4 B)2,4,5 C)1,3,5 D)2,4
Ans:- C)1,3,5
1. A derived class object contains all the base class data.
3.A derived class may not be able to access all the base class data.
5.In inheritance chain construction of object happens from base towards derived.
Q.5.which of the following statements is correct about the c#.NET program given below?
namespace IndiabixConsoleApplication
{
class Baseclass
{
int i;
public Baseclass (int ii)
{
i = ii;
console.Writ("Base");
}
}
class Derived : Baseclass
{
public Derived (int ii ) : base( ii )
{
Console.write("Derived");
}
class MyProgram
{
static void main(string [ ] args )
{
Derived d = new Derived ( 10 );
}
}
}
Ans:-The program will be output : Base Derived
Q.6.which of the following statement are correct about an interface in C#.NET?
Ans:-1.A class can implements multiple interfaces.
2.Structures cannot inherits a class but can implements an interface.
3.In C#.NET, : is used to signify that a class member implements a specific interface
Q.7.Which of the following statements is correct?
Ans:-C.Interfaces members are automatically public.
Q.8.Which of the following are the correct ways to declare a delegate for calling the function func () defined in the sample class given below?
class Sample
{
public int func ( int i , single j)
{
/* Add code Here */
}
}
Ans:-delegate int d (int i , single j );
Q.9.suppose on pushing a button an object is to be notified , but it is not known until run time which object should be notified.Which of the following programming construct should be used to implement this idea?
Ans:-Delegate
Q.10. Which of the following statements is correct?
A. A constructor can be used to set default values and limit instantiation.
B. C # provides a copy constructor.
C. Destructors are used with classes as well as structures.
D. A class can have more than one destructor.
Ans:- A. A constructor can be used to set default values and limit instantiation.
Q.11.Explain Abstract class in C#
Ans:-
Abstract Class :-Abstract class is designed to act as base class
(to be inherited by other classes).
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Abstract_eg
{ abstract class Shape
{
public void Info()
{ Console.WriteLine("This method is defined in Shape Abstract Class ");
}
public abstract int Area(int a, int b);
}
class Rectangle : Shape { public override int Area(int a, int b)
{
return a * b;
}
}
class Program
{
static void Main(string[] args)
{ Rectangle r = new Rectangle();
Console.WriteLine("Area is : " + r.Area(10, 10));
}
}
}
{
Console.write("Derived");
}
class MyProgram
{
static void main(string [ ] args )
{
Derived d = new Derived ( 10 );
}
}
}
Ans:-The program will be output : Base Derived
Q.6.which of the following statement are correct about an interface in C#.NET?
Ans:-1.A class can implements multiple interfaces.
2.Structures cannot inherits a class but can implements an interface.
3.In C#.NET, : is used to signify that a class member implements a specific interface
Q.7.Which of the following statements is correct?
Ans:-C.Interfaces members are automatically public.
Q.8.Which of the following are the correct ways to declare a delegate for calling the function func () defined in the sample class given below?
class Sample
{
public int func ( int i , single j)
{
/* Add code Here */
}
}
Ans:-delegate int d (int i , single j );
Q.9.suppose on pushing a button an object is to be notified , but it is not known until run time which object should be notified.Which of the following programming construct should be used to implement this idea?
Ans:-Delegate
Q.10. Which of the following statements is correct?
A. A constructor can be used to set default values and limit instantiation.
B. C # provides a copy constructor.
C. Destructors are used with classes as well as structures.
D. A class can have more than one destructor.
Ans:- A. A constructor can be used to set default values and limit instantiation.
Q.11.Explain Abstract class in C#
Ans:-
Abstract Class :-Abstract class is designed to act as base class
(to be inherited by other classes).
- Abstract class is a design concept in program development and provides a base upon which other classes are built. *We cannot create an object of abstract class.
- After declaring an abstract class, it cannot be instantiated on its own, it must be inherited.
- We can write abstract and non abstract method in a abstract class.
- In C#, we have ?Abstract? keyword.
- At a time a class can inherit only one abstract class.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Abstract_eg
{ abstract class Shape
{
public void Info()
{ Console.WriteLine("This method is defined in Shape Abstract Class ");
}
public abstract int Area(int a, int b);
}
class Rectangle : Shape { public override int Area(int a, int b)
{
return a * b;
}
}
class Program
{
static void Main(string[] args)
{ Rectangle r = new Rectangle();
Console.WriteLine("Area is : " + r.Area(10, 10));
}
}
}
Q.12.Discuss Delegate in C#
Ans:-
Events:- Objects, known as event senders, trigger events, are fired, when an action takes place, such as user clicking a button,a method completing a calculation, or a network communication being received.
- All events in .NET are handled by delegates.
- To create an event object
- public event MyEventHandler MyEvent;
- A delegate is an object that can refer to a method. Therefore, when you
create a delegate, you are creating an object that can hold a reference to a
method.
method to which the delegate refers.
method.
- It is important to understand that the same delegate can be used to call
method to which the delegate refers.
Example:
using System;
delegate int NumberChanger(int n);
namespace DelegateAppl
{
class TestDelegate
{
static int num = 10;
public static int AddNum(int p)
{
num += p;
return num;
}
public static int MultNum(int q)
{
num *= q;
return num;
}
public static int getNum()
{
return num;
}
static void Main(string[] args)
{
//create delegate instances
NumberChanger nc1 = new NumberChanger(AddNum);
NumberChanger nc2 = new NumberChanger(MultNum);
//calling the methods using the delegate objects
nc1(25);
Console.WriteLine("Value of Num: {0}", getNum());
nc2(5);
Console.WriteLine("Value of Num: {0}", getNum());
Console.ReadKey();
}
}
}
output:
Value of Num: 35
Value of Num: 175
No comments:
Post a Comment