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

Java Java Data Structures Getting There Object Inheritance

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,252 Points

Java Object Inheritance - Review

So here's what I think I understand about Object inheritance in Java.

Object Inheritance

  • A class that is derived from another class is called a subclass (or child class)

  • The class the child class is inherited from is called the super class

  • By doing this the child class inherits the public fields and methods from its parent's class.

  • All classes in Java inherit from a special type called Object. All the methods available on

Object is available to every class we create so by this we're able to write methods that help us perform actions like show strings we write when we're creating an instance of a class..

toString() - This method is one of the provided methods from Object returns a string representation of the object. Returns a string that represents the object. Subclasses can override this method and that is recommended. toString is a public String method that returns no arguments.

Overriding methods

  • To override a method, you simply write a method of the same signature.

  • @Override - Using the Override Annotation is best practice.

  • The Override Annotation helps the compiler at compile time to understand that doing something dfferent with the exposed method than its default behaviour..

  • @Override is nothing more than a hint to the compiler. Overriding is changing the default behaviour of the method. Allows us to perform our own "version" of the method.

e.g.

@Override
public String toString() {
  return "Treet: \"" + mDescription + "\" - @" + mAuthor;
}

How am I doing? :)

Allen C
Allen C
1,448 Points

Great notes, I think that you got everything! :) Are you doing this for every lesson?

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,252 Points

Yea I'm pausing from advancing through the track for a little while because I found that I wasn't picking much of it up and I'm still struggling now.

The notes are derived from the theory and I've tried to put it in my own words where I can. I write notes for each lesson I do but sometimes it just doesn't sink in.

I need to move onto

  • Interfaces
  • Collections Framework
  • Lists
  • Sets
  • Maps

I know I need to get my hands dirty with some code practice but I'm trying to get the theory nailed down as well :)