Click here to Skip to main content
13,558,844 members
Rate this:
 
Please Sign up or sign in to vote.
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!!!
Posted 6-Mar-12 18:52pm
Updated 22-Nov-17 16:34pm
Comments
SAKryukov 7-Mar-12 1:11am
   
Real-time, aha... :-)
--SA
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

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.

Use:

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
Discussion
  Permalink  
Comments
KiranSonawane 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#
UmaShankarPatel 7-Mar-12 1:15am
   
Ok,
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......
ShobanaGeorge 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
User-12736590 4-Jan-17 23:54pm
   
Heart touching answer to all those developers who are confused about interface, even after having industry experirence, like me :)
User-11519491 17-Mar-17 1:29am
   
Got me into tears! Wow
lachhar 8-Aug-17 14:51pm
   
heart-touching explanation. Kudos!!
UmaShankarPatel 24-Aug-17 8:34am
   
Thanks
shabanaparveen 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....
UmaShankarPatel 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.
shabanaparveen 8-Sep-17 13:03pm
   
did i say abstract class in a list...i believe i didn't said that!!!
rukhsardaudzai2 27-Feb-18 0:22am
   
recevie love from pakistan, a remarkable answar. god bless you
rukhsardaudzai2 27-Feb-18 0:23am
   
don all interface in one good line
KiranSonawane 7-Mar-12 1:17am
   
Ahhh!!! Very unique example... Really real time.. my 5+
KiranSonawane 7-Mar-12 1:21am
   
You solution accepted. thanks again
UmaShankarPatel 7-Mar-12 1:21am
   
Your welcome........
SibeeshVenu 3-Aug-14 10:22am
   
My Vote Of 5
UmaShankarPatel 4-Aug-14 0:44am
   
Thanks Venu........
UmaShankarPatel 4-Aug-14 0:46am
   
you can also find some interesting FAQ on Interface
http://www.queryingsql.com/2013/10/interview-faq-on-interface-in-c.html
Santosh-K-Tripathi 15-Mar-15 1:01am
   
5+
santhk 5-Nov-15 9:16am
   
Good answer
User-13252141 6-Sep-17 4:42am
   
nice..!!
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
Comments
KiranSonawane 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.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
v2
Comments
KiranSonawane 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. :)
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

Go through the below link you can get a good example of Interface and abstract class in very easy language

http://shivasoft.in/blog/java/difference-between-interfaceinheritance-abstract-class/[^]

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?[^]
  Permalink  
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web04 | 2.8.180515.1 | Last Updated 22 Nov 2017
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100