C#.NET Multiple choices


Total available count: 28
Subject - Microsoft Technologies
Subsubject - C#.NET

A static method____


 

 

 

 



D


Solution:-

A static method in C# is a method that keeps only one copy of the method at the Type level, not the object level. Static methods are called by using the class name, not the instance of the class. The Console class and its Read and Write methods are an example of static methods. The following code example calls WriteLine and Console.

Using Static Method usually, define a set of data members for a class, and then every object of that class will have a separate copy of each of those data members. Let's have an example on static method as follows:

class Program 
 { 
   public int myVar; //a non-static field 
    static void Main() 
   { 
     Program p1 = new Program(); //a object of class 
     p1.myVar = 10; 
     Console.WriteLine(p1.myVar); 
     Console.ReadKey(); 
   } 
 }


In the above example, myVar is a non-static field so to use this field we first need to create the object of that class. On the other hand, static data is shared among all the objects of that class. That is, for all the objects of a class, there will be only one copy of static data.




Next 5 multiple choice(s)

1

Which of the following interface to be implemented to disponse an object externally?

2

Creating a static class is the same as creating _______

3

By default interface methods are?

4

What will be the output of the below?

class BaseClass
{
  public void Slightbook()
  {
     Console.WriteLine("SlightBook questions");
  }
}
class DerivedClass:BaseClass
{
  public void Slightbook()
  {
     Console.WriteLine("SlightBook choices");
  }
}
class program
{
  static void Main(string[] args)
  {
     BaseClass bd = new DerivedClass();
     bd.Slightbook();
  }
}

 

5

Which of the following is correct about the below declaration?

public class A
{
     public virtual void Slightbook(){}
}
public class B:A
{
     public sealed override void Slightbook(){}
}

 

Comments