• Post Reply Bookmark Topic Watch Topic
  • New Topic

what is the main resaon for con't create object for abstract class  RSS feed

 
Venkat Navuri
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Frndz,

I am new to java .I have a doubt on Abstract class


Thanks in advance
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not "Frndz", please.

That is how it is defined. That is the meaning of "abstract".
The reason you can't create an object of an abstract class is that an abstract class is defined as one you can't create an object of.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abstract classes may have abstract methods - methods without an implementation. What should the JVM do if you try to call such a method?
 
saravanan ragunathan
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

we cant use abstract class for creating objects ..because abstract class has atleast one or more abstract methods(method without definition )
but you can extend the abstract class by defining all the abstract methods in that and create the object by using the sub class..
one main thing in this is when you miss to define one or more abstract method ..your sub class also must be an abstract class..


 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
saravanan ragunathan wrote:because abstract class has atleast one or more abstract methods(method without definition )

No it doesn't. The following is perfectly legal:
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
saravanan ragunathan wrote:. . .because abstract class has atleast one or more abstract methods(method without definition ) . . .
As Rob has already said, that is not quote correct. The reason is that "abstract" means untouchable and not solid, so it is used in Java™ to mean "don't create any objects of this class".

You can actually create instances of an abstract class as an anonymous class, but that is a different story.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!