• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

abstract class

 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,


Why we cannot create object for Abstract Class?as far i know Because it contain abstract method.Apart from it any other reason?


Thanks in advance
 
lowercase baba
Posts: 13003
66
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you know what it means to have an abstract method?

So if you did create one, what would happen if you called the method?

And wouldn't that be reason enough?
 
Bartender
Posts: 11445
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

priyanaka jaiswal wrote:as far i know Because it contain abstract method.


Not really. You can create an abstract class without having any abstract methods too !
 
Greenhorn
Posts: 2
PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe the answer to your question has a lot to do with the meaning of abstract. As you said, a class can be abstract without any abstract methods but is it really an abstract class at that point? Abstraction is synonymous with theory. In the aspect of programming, your abstract classes provide a theory of implementation but not the full implementation.
 
Marshal
Posts: 74054
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch Patrick Housley.

You can of course create an object of an anonymous class, which is as near as you will ever get to instantiating an abstract class.
 
Greenhorn
Posts: 26
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Priyanka,

Hope you do understand the wightage of what you said

it contain abstract method

. I have written a small peice of code to illustrate it




Hope this example helps.

 
Ranch Hand
Posts: 36
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mostly use will use abstract class to have contract with all child classes that implements it in a way that child classes must provide the implementation for the methods which are declared as abstract in parent class(unless the child class is also abstract).
For Example:- you may declare class Animal as abstract and let us say you have abstract method walk() in this class, then all the child classes(let us say Dog and Cat) must define how both these animals walk.
So you can not create object of Animal class because if you look it in a broad way then animal is an abstract term for all the animals and each type of animal will have its own walking style.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic