Goldman Sachs Interview Question


Country: United States




Comment hidden because of low score. Click to expand.
5
of 9 vote

Suppose there is a class Company and has method cometToOffice().
There are various types of employees in the company. Some(Say All Managers) are having personal Cars and others(Say Salesmen) uses public transport to go office.
Then for both (Manager and Saleman ) you will write separate method comToOfficeByCar() and ComeToOfficeByPublicTransport(). This is not we want in java. If suppose there are 100 ways by which employees go to office. Then you will have to write separate method for them too.
Using OOP what you can do is this. override the ComToOffice method in each subclass of Company and you will not need to remember the names of 100s of various functions.
And also you can put the general functionality in the super class method and call it using super keyword whenever required.
I hope this example helped you somehow :)

- Deven Bhooshan July 11, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 votes

I think what the example you gave fits well for interface.The need of overridng is improving a particular method or making it completely new or get the best out of two super classes etc.

- Raviteja July 13, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Please explain what you want to tell with examples. :)

- Deven Bhooshan July 13, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

method toString in the Object returns
getClass().getName() + "@" + Integer.toHexString(hashCode()).

To convert Integer, Float, Double to string we have to write methods like integerToString, floatToString and doubleToString. Say if we have n classes we have to have to remember N diff method names.

Than this we can override already existing method and return correct values.

- Anonymous August 02, 2012 | 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