• Post Reply Bookmark Topic Watch Topic
  • New Topic

abstract class  RSS feed

 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • 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
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • 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
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • 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
Java PHP
  • Mark post as helpful
  • send pies
  • 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: 56608
172
  • Mark post as helpful
  • send pies
  • 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
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!