• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

About Abstract Class

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
The harder you work, the luckier you get. This tiny ad brings luck - just not good luck or bad luck.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic