May 9, 2019

Srikaanth

NetApp C# Interview Questions Answers

When Do You Generally Use A Class Over A Struct?

A class is used to model more complex behavior, or data that is intended to be modified after a class object is created. A struct is best suited for small data structures that contain primarily data that is not intended to be modified after the struct is created.

List The 5 Different Access Modifiers In C#?

1. public
2. protected
3. internal
4. protected internal
5. private

If You Donot Specify An Access Modifier For A Method, What Is The Default Access Modifier?

private.

Classes And Structs Support Inheritance. Is This Statement True Or False?

False, Only classes support inheritance. structs donot support inheritance.

If A Class Derives From Another Class, Will The Derived Class Automatically Contain All The Public, Protected, And Internal Members Of The Base Class?

Yes, the derived class will automatically contain all the public, protected, and internal members of the base class except its constructors and destructors.

Can You Create An Instance For An Abstract Class?

No, you cannot create an instance for an abstract class.

How Do You Prevent A Class From Being Inherited By Another Class?

Use the sealed keyword to prevent a class from being inherited by another class.

Classes And Structs Can Be Declared As Static, Is This Statement True Or False?

False, only classes can be declared as static and not structs.

Can You Create An Instance Of A Static Class?

No, you cannot create an instance of a static class.

Can A Static Class Contain Non Static Members?

No, a static class can contain only static members.

Does C# Support Multiple-inheritance?

No, but you can implement more than one interfaces.

Who Is A Protected Class-level Variable Available To?

It is available to any sub-class (a class inheriting this class).

Are Private Class-level Variables Inherited?

Yes, but they are not accessible. Although they are not visible or accessible via the class interface, they are inherited.

Describe The Accessibility Modifier "protected Internal".

It is available to classes that are within the same assembly and derived from the specified base class.

What's The Top .net Class That Everything Is Derived From?

System.Object.
NetApp Most Frequently Asked Latest C# Interview Questions Answers
NetApp Most Frequently Asked Latest C# Interview Questions Answers

Give An Example To Show For Hiding Base Class Methods?

Use the new keyword to hide a base class method in the derived class as shown in the example below.
using System;
public class BaseClass
{
public virtual void Method()
{
Console.WriteLine("I am a base class method.");
}
}
public class DerivedClass : BaseClass
{
public new void Method()
{
Console.WriteLine("I am a child class method.");
}
public static void Main()
{
DerivedClass DC = new DerivedClass();
DC.Method();
}
}

Can You Access A Hidden Base Class Method In The Derived Class?

Yes, Hidden base class methods can be accessed from the derived class by casting the instance of the derived class to an instance of the base class as shown in the example below.
using System;
public class BaseClass
{
public virtual void Method()
{
Console.WriteLine("I am a base class method.");
}
}
public class DerivedClass : BaseClass
{
public new void Method()
{
Console.WriteLine("I am a child class method.");
}
public static void Main()
{
DerivedClass DC = new DerivedClass();
((BaseClass)DC).Method();
}
}

What Is An Abstract Class?

An abstract class is an incomplete class and must be implemented in a derived class.

Can You Create An Instance Of An Abstract Class?

No, abstract classes are incomplete and you cannot create an instance of an abstract class.

What Is A Sealed Class?

A sealed class is a class that cannot be inherited from. This means, If you have a class called Customer that is marked as sealed. No other class can inherit from Customer class. For example, the below code generates a compile time error "MainClass cannot derive from sealed type Customer. using System;

public sealed class Customer
{
}
public class MainClass : Customer
{
public static void Main()
{
}
}

What Are Abstract Methods?

Abstract methods are methods that only the declaration of the method and no implementation.

How Can You Force Derived Classes To Provide New Method Implementations For Virtual Methods?

Abstract classes can be used to force derived classes to provide new method implementations for virtual methods. An example is shown below.
public class BaseClass
{
public virtual void Method()
{
// Original Implementation.
}
}
public abstract class AbstractClass : BaseClass
{
public abstract override void Method();
}
public class NonAbstractChildClass : AbstractClass
{
public override void Method()
{
// New implementation.
}
}

When an abstract class inherits a virtual method from a base class, the abstract class can override the virtual method with an abstract method. If a virtual method is declared abstract, it is still virtual to any class inheriting from the abstract class. A class inheriting an abstract method cannot access the original implementation of the method. In the above example, Method() on class NonAbstractChildClass cannot call Method() on class BaseClass. In this way, an abstract class can force derived classes to provide new method implementations for virtual methods.

Can A Sealed Class Be Used As A Base Class?

No, sealed class cannot be used as a base class. A compile time error will be generated.

What Are The 4 Pillars Of Any Object Oriented Programming Language?

1. Abstraction
2. Inheritance
3. Encapsulation
4. Polymorphism

Do Structs Support Inheritance?

No, structs do not support inheritance, but they can implement interfaces.

What Is The Main Advantage Of Using Inheritance?

Code reuse.

Does C# Support Multiple Class Inheritance?

No, C# supports single class inheritance only. However classes can implement multiple interfaces at the same time.

Can A Struct Have A Default Constructor (a Constructor Without Parameters) Or A Destructor In C#?

No.

Can You Instantiate A Struct Without Using A New Operator In C#?

Yes, you can instantiate a struct without using a new operator.

Can A Struct Inherit From Another Struct Or Class In C#?

No, a struct cannot inherit from another struct or class, and it cannot be the base of a class.

Can A Struct Inherit From An Interface In C#?

Yes.

Are Structs Value Types Or Reference Types?

Structs are value types.

What Is The Base Type From Which All Structs Inherit Directly?

All structs inherit directly from System.ValueType, which inherits from System.Object.

What Do You Mean By Saying A "class Is A Reference Type"?

A class is a reference type means when an object of the class is created, the variable to which the object is assigned holds only a reference to that memory. When the object reference is assigned to a new variable, the new variable refers to the original object. Changes made through one variable are reflected in the other variable because they both refer to the same data.

What Do You Mean By Saying A "struct Is A Value Type"?



A struct is a value type mean when a struct is created, the variable to which the struct is assigned holds the struct's actual data. When the struct is assigned to a new variable, it is copied. The new variable and the original variable therefore contain two separate copies of the same data. Changes made to one copy do not affect the other copy.

https://mytecbooks.blogspot.com/2019/05/netapp-c-interview-questions-answers.html
Subscribe to get more Posts :