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
Oshedhe Munasinghe
8,108 PointsSupertype?
I don't understand the meaning supertype, is it something to do with object or generics?
Please give me some example codes
2 Answers
jcorum
71,830 PointsIf one class, e.g., Lawyer, extends another class, e.g., Employee, in an inheritance heirarchy then the former is called the subclass and the latter is called the superclass, and you can create objects like e below which are an Employee at compile time but a Lawyer at runtime:
Employee e = new Lawyer();
Employee is also said to be the type of e. In fact sometimes type is used as a synonym for class. So if a class is a superclass it could be called a supertype. That's not quite accurate, however, because interfaces are also types, so though classes are types, types are not necessarily classes.
Oshedhe Munasinghe
8,108 PointsSo if I have understood from your comment that
Employee is a Supertype
Lawyer is a Subtype
e is a ref. variabel to Emplyee
which means that Lawyer cant reach Employee methods! Right? (well it can if I do type cast)