Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Any real world example for Abstract & Interface?

As the title said about any example for abstract and interface example for Java or C#. I know how to use it but I am always stuck how and where it can be use?

Craig Dennis
Craig Dennis
Treehouse Teacher

Hi Vijesh Arora !

Did these answers help you get unstuck? If they did, please choose best answer, and if not, let me know and I can try to break it down a bit for you!


2 Answers

Abstract classes and Interface classes both have similarities in that they are only meant for adding to code for the purpose of using their methods. When you instantiate an abstract object you can use any number of methods. Interfaces, however, once you implement it you have to use ALL of the methods. For Example,
I was working on a program the other day where I had to use a Graphics Object (Abstract) in my JPanel- the graphics object has many methods to choose from but you only add what you need. And then I had to implement the KeyListener interface so I could return the keys being pressed. In order to use the KeyListener I had to add in all of its five methods which I only needed to use one so the other four just set there empty. Does that make any sense?