C#.NET Multiple choices


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

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();
  }
}

 


 

 

 

 



C


Solution:-

Inheritance (Derived and Base Class)
In C#, it is possible to inherit fields and methods from one class to another. We group the "inheritance concept" into two categories:

Derived Class (child) - the class that inherits from another class
Base Class (parent) - the class being inherited from
To inherit from a class, use the: symbol.

In the example below, the Car class (child) inherits the fields and methods from the Vehicle class (parent):

Example:-

class Vehicle // base class (parent)
{
 public string brand = "Ford"; // Vehicle field
 public void honk()       // Vehicle method
 {          
  Console.WriteLine("Tuut, tuut!");
 }
}

class Car : Vehicle // derived class (child)
{
 public string modelName = "Mustang"; // Car field
}

class Program
{
 static void Main(string[] args)
 {
  // Create a myCar object
  Car myCar = new Car();

  // Call the honk() method (From the Vehicle class) on the myCar object
  myCar.honk();

  // Display the value of the brand field (from the Vehicle class) and the value of the modelName from the Car class
  Console.WriteLine(myCar.brand + " " + myCar.modelName);
 }
}

 




Next 5 multiple choice(s)

1

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(){}
}

 

2

Which of the following field cannot be virtual?

3

What is the use of a new keyword in polymorphism?

4

Which of the below is not a built-in delegate?

5

Which of the below is not a way to return multiple values?

Comments