Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
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?
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?