my dog learned polymorphism*
The moose likes Beginning Java and the fly likes Abstract classes and Interfaces in Project Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Abstract classes and Interfaces in Project " Watch "Abstract classes and Interfaces in Project " New topic
Author

Abstract classes and Interfaces in Project

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Hi
This is a interview question .

Please tell me whether it is good to use Interfaces or abstract classes in a project ??

Actually i don't see any usefulness in using a Abstarct class


Save India From Corruption - Anna Hazare.
rohan yadav
Ranch Hand

Joined: Oct 13, 2009
Posts: 156
Hi Ravi, I think its good to use Interfaces and Abstract classes in your program, as it will increase encapsulation and promote code reusability.


Sage of The Monstrous Toad of Mount Myoboku
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Ya i know we need to use Interfaces as Data Access Layer , but still cant get where Abstract classes will be useful actually . any scenario ??
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Base functionality.

Do you have access to Google or other search engine?!
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18874
    
  40

Ravi Kiran V wrote:
This is a interview question .

Actually i don't see any usefulness in using a Abstarct class


Hopefully, you didn't answer this as such during the interview !

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Hiram Nascimento
Greenhorn

Joined: Jul 09, 2009
Posts: 13
Hi Ravi,

The key usefulness of Interfaces and Abstract classes is Polymorphism.

Also, once Java doesn't support multiple inheritance, Interfaces resolves the "Diamond of Death" problem if you know how to use them.

They also provide advantages for your application's design.

Did I convince you?

regards,
Hiram
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Did I convince you?


some what

The question is not about my class extending multiple classes at same time .

But i use interface to define a contact but when to go with Abstrat class actually ??
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39044
    
  23
Ravi Kiran V wrote:But i use interface to define a contact but when to go with Abstrat class actually ??
Google is your friend
Hiram Nascimento
Greenhorn

Joined: Jul 09, 2009
Posts: 13
An interface is a fully abstract class that only defines a contract and has no implementation.

All interface methods are implicitly public abstract.

The abstract classes accept you to define a contract but also allow you to implement some methods (which are concrete).

So, if you have a fully abstract class you have an Interface, if you have a partial abstract class you can have an Abstract Class, but if you have fully concrete class you have a normal Class.

Hiram
 
GeeCON Prague 2014
 
subject: Abstract classes and Interfaces in Project