Abstract Classes

  • Simran
  • Born
  • Born
  • Simran
  • Posts: 3

Post 3+ Months Ago

Please tell me What is an Abstract classes? Please tell me.I'm waiting for your reply.

Thanks In Advance. :idea:
  • spork
  • Brewmaster
  • Silver Member
  • spork
  • Posts: 6302
  • Loc: Seattle, WA

Post 3+ Months Ago

Abstract classes are classes that can be defined but not instantiated. They often contain abstract methods, which require subclasses that inherit from the abstract class to define the behavior for such methods.

For example, I may be writing a program that manages employees. Say my company has two types of employees - hourly and salaried. I could create two classes to represent them: HourlyEmployee and SalariedEmployee.

But since the two classes have a lot of data/functionality in common (name, position, etc), I'd want to place that information in a common superclass, Employee, and have my two specific employee classes extend it.

But since employees must be of one type or the other, we don't want the Employee class to ever be instantiated directly -- we must force instantiation of the subclasses. For this reason, we make the Employee class abstract.

Additionally, say we had a method in our class called getPayRate(). This method will exist for both employee types, but its functionality will be different for each type. We can declare getPayRate() as an abstract method in our abstract Employee class. This forces HourlyEmployee and SalariedEmployee to define the behavior individually.





Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 51 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum

© 1998-2017. Ozzu® is a registered trademark of Unmelted, LLC.