Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Inheritance help  RSS feed

 
Jim Bain
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am learning about inheritance and for the most part I understand all the concepts along with polymorphisms. What I don't understand is how these ideas fall into building a real world application. If someone could, please point me to some code examples that embrace inheritance and polymorphisms. I would like to see how they work in a large application/program. Don't point me to a general Dog extends Animal example, I get the concept. I guess I'm just trying to bridge everything together.

Thanks, Jim
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jim,

Welcome to JavaRanch!

Well, one example is probably right under your nose: Java's Swing and AWT APIs. Everything you can see on the screen is a Component. Some Components are Containers (JPanel, JFrame) because they can contain other Components. Other Components represent "widgets" like JButton, JComboBox, JTree, JList... Every one of these objects is very different from the others, but they all have identical methods to set the size, color, font... all inherited from Component. Obviously each Component has to react differently to be told to resize itself (for example). But to tell a Component to resize itself, you can just call setSize(), not matter what subclass of Component it is.
 
Jim Bain
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ernest,

Thanks for the reply, looking over the awt/sing api has been very helpful!

Jim
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!