hi All

i have a question. plz answer if u can. i must b very thankful to u

question is

Why use abstract classes at all? Why not just declare a class and then make sure you never instantiate any variables of that type?

thnx in advance

Recommended Answers

All 3 Replies

>Why use abstract classes at all?

Sometimes you may want to declare a class and yet not know how to define all of the methods that belong to that class.

For example, you may want to declare a class called Writer and include in it a member method called write(). However, you don't know how to code write() because it is different for each type of Writer Device. Of course, you plan to handle this by deriving subclasses of Writer, such as Printer, Disk, Network and Console.

> Why use abstract classes at all? Why not just declare a class and
> then make sure you never instantiate any variables of that type?

...because compile time checks are far superior/efficient when compared to your code blowing up at run time. Languages which don't have the concept of Abstract classes baked in reply on hacks to achieve the same [e.g. Actionscript 3].

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.