answersLogoWhite

0

What is abrstac class and virctulfunction in c sharp?

Updated: 8/19/2019
User Avatar

Wiki User

13y ago

Best Answer

abstract class is a class label with abstract. It is just like a common class, with the following characterics:

1. Abstract class cannot be instantiate with an instance.

2. Abstract class may have abstract methods, while the normal class cannot have abstract methods.

a virtual function in C# is a way to provide a default implementation for the class hierarchy. Both abstract class and common class (not sealed) can have virtual methods/ functions.

Note that an abstract method (of an abstract class) is defining the intent, no codes (no default behavior), the implementation are left for the derived classes to do so. The virtual function if defined in an abstract class must define the implementation, the minimum is to do nothing:

public abstract class Vehicle {

public abstract int GetNumberOfTires();

public virtual void Move() { // default is doing nothing}

}

public class Car : Vehicle {

public override int GetNumberOfTires() { return 4; }

public override void Move() { throws new OutOfFuelExpection(); }

}

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is abrstac class and virctulfunction in c sharp?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Which class is used to define the controls in c sharp?

.Ascx class file is used to define the controls in c#


How can you store Class properties in Array in c sharp?

vcbvcbcvb


What is class in c sharp?

A class contains methods that can be used in different programs and can be transfered and reused.


What is the difference between abstarct class and virctulfunction in C sharp?

They are not comparable, but may have some relationship between them.An abstract class is a class, while a virtual function (or method) is a method. A method must exist within a class. Hence, a class has methods, and the methods may be defined as virtual functions.A virtual function must be defined in a class, but that class does not have to be an abstract class. However, the purpose of a virtual function in C# is to provide a default behavior/implementation, while allowing the derived class to override that default implementation, hence it makes no sense to define a virtual function in a sealed class (a leaf, that is, no class can extend from it, and it is not an abstract class)Example:public class Parent {public virtual string MostCommonPhrase() {return "You better listen to me...";}}public class Child : Parent {public override string MostCommonPhrase() {return "You never listen to me...";}}


What is abstarct class in C sharp?

This is like a tamplate. You make this kind of class and than later you can override it and put it to use.


What are the notes to?

A sharp G G E sharp G E sharp A sharp A sharp C C A sharp C E sharp G A G E sharp A sharp A sharp A sharp G E sharp C this is not on the Flute btw idk what instrument its on


What are the notes to fireflies?

A sharp G G E sharp G E sharp A sharp A sharp C C A sharp C E sharp G A G E sharp A sharp A sharp A sharp G E sharp C this is not on the flute btw idk what instrument its on


How do you play Simpson theme on keyboard?

here it is C,E,F SHARP,A,G,E,C,A,F SHARP,F SHARP,F SHARP,G,A SHARP,C,C,C,C


Can methods in c sharp declared outside the class?

C# is a completely object-oriented language, everything is an object. Every datatype, is a superset of the object class. I'm sorry to say, but every method must be declared inside of a class. :(


How do you show a positive integer for example 12345678901234567890 in C sharp that has more than 17 digits?

There is Int64 class, it will do it.


What is the difference between destructors in c plus plus and c sharp?

In C# only class instances can have a destructor, whereas both class and struct instances can have a destructor in C++. While syntactically similar, a C++ destructor executes exactly as written, whereas a C# destructor merely provides the body of the try clause of the class' finalize method.


What key signature has G sharp B sharp and C sharp?

C# Major