• Post Reply Bookmark Topic Watch Topic
  • New Topic

About Abstract Class  RSS feed

 
Gaurav Agarwal
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all
I just want to know that why we can not make a object of abstract class??


Thanks in advance
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because abstract means that it is not a full class definition. It is incomplete. Either explicitly it's declared abstract or it become abstract because there is a method that's part of the class that isn't implemented.
 
Prashanth Lingala
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gaurav,
i presume you know in Object Oriented parlance,
we have superclass and derived class.
Now let us say we have a problem where we have to find the area
of a two dimensional figure...
how will you do it???
so you have an abstract class which has a abstract method called calculateArea()...
we have the method abstract since the deriving class can be a triangle(which is a two dimensional figure), or a circle(again a 2d figure),
it doesnt make sense to implement calculateArea() in superclass,
so we declare the method abstract,
now the moment we declare an abstract method the enclosing class has to be abstract,
by abstract we mean we only know what it should do, but not how it should do...
this implementation is specific and is left for the deriving classes,
the deriving class have to override the abstract method or they themselves have to be declared abstract...
hope this helps,

Regards
Prashanth Lingala
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An abstract class is just as its name implies, an Abstraction.

A Circle, a Square, and a Triangle all have some things in common. They are all shapes and their commonalities can be encapsulated within Shape. However, does it make any sense at all to have an instance of a Shape? What is a shape? Without the added qualities that make a Shape a Cirle or a Square, a Shape is really nothing at all.

An Abstract Class in Java is just a reflection of that. Use abstract classes to "abstract away" commonalities of your subclasses into a single class so that you don't have duplicate code.
 
kiennjal shah
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Corey rightly said:
An abstract class is just as its name implies, an Abstraction


The reason it cannot be instantiated is, coz well it is too abstract. For instance if we were to create an object of an abstract class, there would be all these questions about the behavior of it's methods, initialization of the variables etc...this is something generic, which should be extended such that subclasses can actually define methods as per their requirements.

Abstraction, one of the benefits, OOP offers

Have a good one!

-Kiennjal
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!