Goldman Sachs Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
2
of 2 vote

Interface provides method signature and not the body. Its up to the developers to
provide body for these methods once they implement it.

Abstract provides both methods with and without body. Adding new methods in abstract class in middle of development life cycle won't break existing sub classes unless these methods are declared as mustoverride. If there are frequent addition of new methodsproperties and so on. one should use abstract..

Adding new methods to the interface will force users to go through each and
every sub class that implemented that interface and call these methods.
So its always preferred to use abstract over interface because of this limitation.

Whereas on the other hand interface can fill gap of multiple inheritance. One can
implement from more than one interface. Not same with Abstract. One can inherit
from only one abstract class.

If you want to inherit from class that can provide reusable code then use abstract class. For instance connecting to the database or base class for grid or treeview.
If you implement your subclass from an interface then in each subclass you will have to write your own code to fill body of these methods.

Hope this helps.

- Shri February 19, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Interface vs. abstract class
Choosing interfaces and abstract classes is not an either/or proposition. If you need to change your design, make it an interface. However, you may have abstract classes that provide some default behavior. Abstract classes are excellent candidates inside of application frameworks.

Abstract classes let you define some behaviors; they force your subclasses to provide others. Those services allow your application to plug in to your application framework. However, there is some application-specific functionality that only your application can perform. Such functionality might include startup and shutdown tasks, which are often application-dependent. So instead of trying to define that behavior itself, the abstract base class can declare abstract shutdown and startup methods.

- AnastasiaVip May 25, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 0 votes

bite me

- princess October 02, 2007 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

java doesn't allow multiple inheritance. that's where interfaces come in.

but you cannot implement any method inside an interface. so if u need to implement some methods and leave others with only the declaration(prototype) better use abstract classes.

- evil grin July 23, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I would say interface is to define the external structure of a class while the abstract class is to define the internal structure of a class.

- blue monkey February 27, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Use Abstract class when you are designing a family inheritance.
eg.,
Animal
| |
DOG CAT

Use interface to provide additional behavior for a class... eg., Swimmable interface implemented by Fish and by Swimmer.

Fish and Swimmer do not have anything in common except that they both can swim.

- DD April 11, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

download.oracle.com/javase/tutorial/java/IandI/abstract.html

abstract classes are most commonly subclassed to share pieces of implementation. A single abstract class is subclassed by similar classes that have a lot in common (the implemented parts of the abstract class), but also have some differences (the abstract methods).

Multiple interfaces can be implemented by classes anywhere in the class hierarchy, whether or not they are related to one another in any way.

- running July 27, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Existing class hierarchy can be easily retrofitted to add new behavior using interfaces. Interfaces allows to define mixed behaviors. Interfaces allows constructions of non-hierarchial frameworks.
Abstract classes are easy to evolve. Adding new behavior to abstract classes is simpler than interfaces.
Prefer abstract classes if simplicity is more important than flexibility.

It is worth reading Item 18 in Effective Java to understand why to prefer interfaces over abstract classes.

- Survivor January 21, 2013 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More