Goldman Sachs Interview Question
Country: United States
An interface has a number of usages.
1. We will adopt the great principle of P2I - program to interface. By which we will not adhere to the concrete implementation of rather to the interface, which will give a room for change later on
2. They act as contract for management. Any class which claims that it is implementing the interface shall adhere to the contract so that we are sure whenever we are using that class, the contract is satisfied - even without looking into the actual code
Real time examples - collection classes of Java -
Interface:-- Simply we can say that interface is the contract among the Technology and devloper and we cmply we can say that Interface is the standards which implements by programmers...
Real life Example:-- Simply real life ex of intreface is Credit card how-- if there is any market in india which has all country shop
if u hv only rupss u cn soping only india's shop by credit card u can sopping from any country'shop means by interface we can implements according to u(programmers)
As i understand it, Interfaces are the minimum contract that helps manage classes that extend them. On windows systems, all plugins extend IUnknown interface of windows. This way of contractual programming makes it possible to develop applications in future as long as all the components in future are guaranteed to agree to the interface.
The real importance of interfaces in Java can be explained by looking at the Collections API.
Lets take an example of interface List. It defines a contract that every implementing class must implement, while giving them the independence of implementing it the way they want. The main advantage of using an interface over here as opposed to using an abstract class is that a single implementation can bind to multiple contracts.
For example, the class LinkedList implements interface Queue as well as List. If they would've been abstract class, LinkedList wouldnt have been able to extend both of them at the same time.
Another example i would like to add is interface Serializable. This is called a marker interface as it doesnt contain any method that the implementing classes needs to define. It is solely used by the JVM to identify whether the state of the class can be saved or not.
Not knowing about Java so much... But in general for the programming wise, if you want to implement some sort logic, disposal logic by your own, if you implement appropriate interfaces to your class e.g.) IComparator, IDisposal or etc..., you can define your own behavior for the corresponding methods and that's the most beneficial cases for using built-in interfaces.
Maybe, I'm describing about polyrhythm and bit pointless as an answer...
There seems to be a lot of (probably self-) promotion of these saurabhschool videos going on on this website.
I did check out the collection of videos at some point. In terms of the algorithmic stuff, they are by no means comprehensive of what you need to know for tech interviews, but the quality and depth of discussion on the questions that are covered is decent.
But I don't recall anything there that discussed interfaces or OO. If you're going to promote some other website, can you at least include a link to the specific video that covers the material?
An interface (in Java) is used to for inheritance i.e to create a super class sub class relationship. Any class that implements this interface will inherit all the methods of the interface .
- nk July 25, 2012