File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes I got stuck in this interview question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "I got stuck in this interview question" Watch "I got stuck in this interview question" New topic
Author

I got stuck in this interview question

Thill Sivam
Greenhorn

Joined: Oct 14, 2009
Posts: 9
Hi all,
I just attended java interview .. one quesion is 'what is the use of an abstract class without any abstract method ???

I just replied, there is no use.... Is it right?
Manish Singh
Ranch Hand

Joined: Jan 26, 2007
Posts: 160
only possible use is that the intention is to stop that class from being instantiated.

If I consider the code for an organization



and the organization always want to have the employee classified into one of the above type.

Jim Hoglund
Ranch Hand

Joined: Jan 09, 2008
Posts: 525
Ooops... Yes, a class can be declared abstract even without an abstract method.
This is done when default methods are provided, but it is expected that some/all
methods will be overridden before the class is instantiated with new.
Jim ... ...


BEE MBA PMP SCJP-6
Thill Sivam
Greenhorn

Joined: Oct 14, 2009
Posts: 9
@Jim,

can you explain a little bit..? thanks.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12823
    
    5
It is a design decision by the programmer as part of a larger architecture.

I have done it simply to remind myself of the purpose of the class when looking at the code years later.

Bill
Lee Kian Giap
Ranch Hand

Joined: Jan 23, 2008
Posts: 213
@Jim,


expected that some/all methods will be overridden before the class is instantiated with new.


sorry, need to correct your sentence a little bit ... it sounds correct and sounds wrong ...

"all abstract methods need to be implemented on the first concrete class that inherit the abstract class"


SCJP 6, SCWCD 5, SCBCD 5
Lee Kian Giap
Ranch Hand

Joined: Jan 23, 2008
Posts: 213
@Thill

normally in practical , in between of interface and abstract class ...
if you don need any implemted method (i.e. all methods is abstract), you will choose interface
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Lee Kian Giap wrote:@Jim,
Jim wrote:
expected that some/all methods will be overridden before the class is instantiated with new.

sorry, need to correct your sentence a little bit ... it sounds correct and sounds wrong ...

"all abstract methods need to be implemented on the first concrete class that inherit the abstract class"

Except that the question specifically stated there were no abstract methods, so the sentence is already correct (mostly--none of the methods would *have* to be overridden, since it's only the class itself that is abstract).
Jim Hoglund
Ranch Hand

Joined: Jan 09, 2008
Posts: 525
The javax.swing package has several abstract classes with fully implemented methods.
The class AbstractButton, for example, has a very long list. The strategy is that in your
concrete class you will override only the few methods that you intend to use. Jim ... ...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I got stuck in this interview question