wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Abstract Class does not have abstract method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Abstract Class does not have abstract method" Watch "Abstract Class does not have abstract method" New topic
Author

Abstract Class does not have abstract method

Arulkumar Gopalan
Ranch Hand

Joined: Oct 13, 2003
Posts: 104
# We can have an abstract class, which does not have an abstract method.

Q: What is the purpose of having an abstract class with out having any abstract methods?

Any answer other than "to avoid creating instance for that class" is appreciated.
[ July 28, 2005: Message edited by: Arulkumar Gopalan ]

Anbudan & Mahalo,<br />Arul<br /> <br />-Not a sun certified Java professional :-)
Lalitha Vydyula
Ranch Hand

Joined: Jul 20, 2005
Posts: 69
Hi Arul,
Thats a good question.
A class can be declared abstract even if it does not actually have any abstract methods. Declaring such a class abstract indicates that the implementation is somehow incomplete and is meant to serve as a superclass for one or more subclasses that will complete the implementation. Such a class cannot be instantiated.
Arulkumar Gopalan
Ranch Hand

Joined: Oct 13, 2003
Posts: 104
Thanks for trying on my Q.

Declaring such a class abstract indicates that the implementation is somehow "incomplete"


What is a possible case for incompletion of an abstract class which does not have abstract methods?

Am asking in real implementation perspective.
[ July 28, 2005: Message edited by: Arulkumar Gopalan ]
Georgy Bolyuba
Ranch Hand

Joined: Feb 18, 2005
Posts: 162
Originally posted by Arulkumar Gopalan:
Thanks for trying on my Q.


What is a possible case for incompletion of an abstract class which does not have abstract methods?

Am asking in real implementation perspective.


Maybe you choose wrong forum in that case? I think you sould ask it in OOP forum.


SCJP 1.4 (100%) Done.<br />SCJD (URLyBird 1.2.3 Started)
latha yeduguri
Greenhorn

Joined: Jun 24, 2005
Posts: 17
Did you get an answer for this in any of the forums?
Devender Thareja
Ranch Hand

Joined: Jul 14, 2005
Posts: 187
Originally posted by Arulkumar Gopalan:
# We can have an abstract class, which does not have an abstract method.

Q: What is the purpose of having an abstract class with out having any abstract methods?

Any answer other than "to avoid creating instance for that class" is appreciated.

[ July 28, 2005: Message edited by: Arulkumar Gopalan ]


The only answer is "To avoid creating instance for that class".
There is no other purpose.


Devender Thareja
SCEA, SCBCD, SCJP
Arulkumar Gopalan
Ranch Hand

Joined: Oct 13, 2003
Posts: 104
Actually, I was not convinced that abstract should be used for that, instead of achieving it's original concept of polymorphism.

But, I understand now, that("To avoid creating instance of a class") could be the only answer from the below explanation.

Sometimes, a class that you define represents an abstract concept and, as such, should not be instantiated. Take, for example, food. Have you ever seen an instance of food? Probably not. What you see instead are instances of carrot, apple, and chocolate chip cookies. Food represents the abstract concept of what we can eat. It doesn't make sense for an instance of food to exist.

thx.
[ July 29, 2005: Message edited by: Arulkumar Gopalan ]
Arulkumar Gopalan
Ranch Hand

Joined: Oct 13, 2003
Posts: 104
Having said abstract key word is used only for "to avoid creating instance of a class". But, below explanation says, that should be achieved using private constructor, not through abstract.

A class type should be declared abstract only if the intent is that subclasses can be created to complete the implementation. If the intent is simply to prevent instantiation of a class, the proper way to express this is to declare a constructor (�8.8.10) of no arguments, make it private, never invoke it, and declare no other constructors. A class of this form usually contains class methods and variables. The class Math is an example of a class that cannot be instantiated; its declaration looks like this:


This is just FYI!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Abstract Class does not have abstract method
 
Similar Threads
Abstract Class and methods
ABSTRACT
abstract class
Query Regarding SCJA
Doubt regarding abstract class