Click here to Skip to main content
15,064,101 members
Please Sign up or sign in to vote.
1.14/5 (6 votes)
See more:
Hello Experts,

The question was asked me interview. Assuming that I am 10th standard student and you (experts) are my teachers. How you are going to explain about interface to 10th standard student. Give me the example of real time scenarios. Please do not post the link.

Thanks in Advace!!!
Updated 2-Apr-21 18:09pm
Real-time, aha... :-)

As you know
An interface contains only the signatures of methods, delegates or events. The implementation of the methods is done in the class that implements the interface.
when you implemnt interface You are very much sure ,that the method in the interface is implemented in the class.

You can say Interface is a class which contain all unimplemented methods taht are implemented in Class that implement it.


Suppose you have a project with lot of classes and each class have no. of methods.
So , How you know which class implement perticuler methods.We make interface for each/some classes and implement these interfaces in that class.

See this
Kiran Sonawane 7-Mar-12 1:09am
Everything is correct. You forgot that I am 10th standard student. I dont know methods delegates ..... I don't want technical answer. Forgot about .net/C#
uspatel 7-Mar-12 1:15am
I can try...
Suppose your parents gives you a list of items to purchase,
that list is an Interface that you will implement at time of purchasing.....
Means Before implementing any thing , you list out what you have to done that will be interface......
Shobana George 16-Oct-13 5:03am
Really good
ravithejag 27-Nov-14 4:51am
perfect answer
yuvafun 5-Jan-16 3:31am
This is very very good and perfect answer
Member 12770171 4-Jan-17 23:54pm
Heart touching answer to all those developers who are confused about interface, even after having industry experirence, like me :)
Member 11553850 17-Mar-17 1:29am
Got me into tears! Wow
lachhar 8-Aug-17 14:51pm
heart-touching explanation. Kudos!!
uspatel 24-Aug-17 8:34am
Shabana Parveen 7-Sep-17 7:38am
if in list, it is mentioned that get $10 dress item means then it would be abstract as you can purchase T-Shirt, a cap or anything of 10 dollar!!! BTW all the methods in an interface is abstract. not sure if analogy fits....
uspatel 8-Sep-17 11:56am
It was answered to keep in mind 10th standard student.):
I am trying to answer your doubt, See that list can never be abstract class, that list itself does not have any kind of implementation. The person(class) who are going to implement that list (interface) can implement all the methods in the list or person can play a role of abstract class, some methods he can implement and other he can mention as abstract to his child class. As abstract class can implement the interface in this case abstract class can provide definition to some relevant methods and make other methods as abstract those will be implemented by child class of that abstract class.
Hope it helps.
Shabana Parveen 8-Sep-17 13:03pm
did i say abstract class in a list...i believe i didn't said that!!!
Rukhsar Ahmad 27-Feb-18 0:22am
recevie love from pakistan, a remarkable answar. god bless you
Member 12036567 11-Jun-18 3:22am
Very clear answer.... thank you.
Rukhsar Ahmad 27-Feb-18 0:23am
don all interface in one good line
Kiran Sonawane 7-Mar-12 1:17am
Ahhh!!! Very unique example... Really real time.. my 5+
Kiran Sonawane 7-Mar-12 1:21am
You solution accepted. thanks again
uspatel 7-Mar-12 1:21am
Your welcome........
[no name] 3-Aug-14 10:22am
My Vote Of 5
uspatel 4-Aug-14 0:44am
Thanks Venu........
uspatel 4-Aug-14 0:46am
you can also find some interesting FAQ on Interface
Santosh K. Tripathi 15-Mar-15 1:01am
[no name] 5-Nov-15 9:16am
Good answer
Member 13284141 6-Sep-17 4:42am
I can provide two types of "real world" examples -- one from the business world and onw from the true "real world."
Real World:
You have an Animal class. It is an abstract class, because you cannot instantiate a generic "Animal," but it provides base functionality.
You have many devired classes of Animal. You have HomoSapiens, Platypus, Penguin (which extends Bird, another subclass of Animal), Giraffe, Housefly, etc. Each of these are concrete classes that may be instantiated (of course, there are several levels of abstract classes between these and Animal (like Chordata, etc.)
Now you want to make something fly. What can fly? Birds and Houseflys (among others), so these classes should provide similar functionality, even though they are widely spaced on our inheritance tree. The solution? Make them use interfaces. Bird and Housefly can not both implement the Flyer interface, so whenever we want something to fly, we can use a Flyer object, not caring whether it's a Bird or a Housefly. Likewise, Penguins and Playtpuses can implement the Swimmer interface (and Penguin should throw an IllegalOperationException in any of its Flyer methods, since Penguins cannot fly).
As far as business examples, I have a persistance engine that will work against any data sourcer (XML, ASCII (delimited and fixed-length), various JDBC sources (Oracle, SQL, ODBC, etc.) I created a base, abstract class to provide common functionality in this persistance, but instantiate the appropriate "Port" (subclass) when persisting my objects. (This makes development of new "Ports" much easier, since most of the work is done in the superclasses; especially the various JDBC ones; since I not only do persistance but other things [like table generation], I have to provide the various differences for each database.)
The best business examples of Interfaces are the Collections. I can work with a java.util.List without caring how it is implemented; having the List as an abstract class does not make sense because there are fundamental differences in how an ArrayList works as opposed to a LinkedList. Likewise, Map and Set. And if I am just working with a group of objects and don't care if it's a List, Map, or Set, I can just use the Collection interface.
Hope that this helps
Kiran Sonawane 7-Mar-12 1:19am
My 5+. But check the answer by Uma Shankar Patel. Very simple!!!!
Santosh K. Tripathi 15-Mar-15 0:57am
5+ from me also.
Interfaces are used to encode similarities which classes share, but do not necessarily constitute a class relationship. For instance, a dog and a lion can both run. We would make them inherit the Animal class and then implement Run via an interface IRun.

A beginner book might help you learn this as well.
Kiran Sonawane 7-Mar-12 1:03am
Thanks for reply. I can do this with simple abstract method within class. For instance add abstract method "Run" in animal class. Then why interface? (Please explain with same example)
Abhinav S 7-Mar-12 1:09am
Ok don't think about the Run method. Think about something like Howl - a dog can howl but a lion cannot.
An IHowl interface might be required for a dog.
Santosh K. Tripathi 15-Mar-15 1:03am
good one. 5+
johannesnestler 7-Mar-12 3:23am
I think your answer is "best" - because simple, no deep programming knowledge required. Other answers might be tecnical correct, but if I tell my mom about abstract classes, she would be lost ;-)
Abhinav S 7-Mar-12 3:27am
Thank you. :)
Go through the below link you can get a good example of Interface and abstract class in very easy language[^]

You can also go through the below link in which there was a discussion of interface and abstract classes... which will help you to understand concept more

Real world examples of abstract classes and interfaces?[^]
Best Explanation will be like
Interface is a contract agreement and class that implements is builder.
When you go to buy a house you put an agreement to a builder with requirements you want one window, two bedrooms, two bath rooms etc(these are interface declaration) and the class which inherits interface is builder, failing to implements any of the requirements is violation of agreement (throws compilation error failing to implements any of the interface method.
Hope this help better understanding
Richard Deeming 6-Apr-21 10:00am
Not only nine years late, but incorrect and misleading.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900