Forums Register Login

Abstract classes and Interfaces in Project

+Pie Number of slices to send: Send
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

+Pie Number of slices to send: Send
Hi Ravi, I think its good to use Interfaces and Abstract classes in your program, as it will increase encapsulation and promote code reusability.
+Pie Number of slices to send: Send
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 ??
+Pie Number of slices to send: Send
Base functionality.

Do you have access to Google or other search engine?!
+Pie Number of slices to send: Send
 

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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
 

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 ??
+Pie Number of slices to send: Send
 

Ravi Kiran V wrote:But i use interface to define a contact but when to go with Abstrat class actually ??

Google is your friend
+Pie Number of slices to send: Send
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
Shiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1444 times.
Similar Threads
Doubt
interfaces and abstract class
Difference Between Abstract Class and Interface
Abstract Classes & Interfaces
interfaces and abstract classes
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 22:57:05.