answersLogoWhite

0


Best Answer

public abstract class Person {

// derived classes must provide the implementation

public abstract string getTitle();

}

public class Female : Person { public override string getTitle() { return "Ms"; } }

public class Male : Person { public override string getTitle() { return "Mr"; }}

Person boy = new Male();

Person girl = new Female();

Console.Write(" {0} vs {1}", boy.getTitle(), girl.getTitle());

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: C sharp program on abstract class and abstract method?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

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. :(


Can anyone 1 pls give a real time example and usage of abstract class and interface in c sharp?

Abstract classes and Interfaces are both examples of contracts with no default implementation. Interfaces are more readily interchangeable between applications (because they can be interpreted as jump tables). Because of this COM in Windows makes heavy usage of interfaces with several master ones being the source of all functionality (e.g., IUnknown). If a programmer wanted to define a type of thing (e.g., MusicalInstrument), that had certain abilities (e.g. Play) without defining how a MusicalInstrument plays... This could be done with an Interface or an Abstract class. If the programmer wanted to provide some base functionality to whomever was going to implement this functionality (e.g., Vloume, Output Stream) then this would be more appropriate for an Abstract class. Abstract classes can even build on interfaces: public interface IMusicalInstrument { void Play(); } public abstract class MusicalInstrument:IMusicalInstrument { private int vol = 10; public virtual SetVolume(int newVol){vol = newVol;} public abstract void Play(); } public class Horn:MusicalInstrument { public override void Play(){//* Play something *//} }


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

vcbvcbcvb


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.


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.

Related questions

What is abrstac class and virctulfunction in c sharp?

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


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...";}}


How is hiding method different from overriding method in c sharp?

Hiding means a class cannot see the definition. Overriding implies that a class must see that to "override"


How do you program a sharp remote to a sharp tv?

you dont


How do you program a cash register sharp XE A21s?

how to program sharp cash register xe-a21s


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. :(


Write a program in c to display welcome to the world of c sharp?

#include<stdio> #include<conio> class program { namespace display { console.println("write your text"); } } correct me if im wrong im a new programmer.


What is a ocelot's method of defense?

sharp claws and teeth


How do youp make cake in sharp microwave oven?

what is the method of baking cake in SHARP microwave oven


How Do you Program a Sharp Aquos remote control to control a Sony tv?

Sharp Aquos is a brand of TV. You can't program it to control another brand of TV.


What POS machine is the easiest to program?

Sharp's ER-A440 is very easy to program.


Can you use random method in If Statement in c sharp?

Yes