Java inheritance ebook

Java inheritance provides powerful ways to write Java applications, but you need to know the difference between interfaces and abstract classes.

This edition covers inheritance keywords to design patterns with examples of multiple inheritance, how to override methods and use abstract classes for tiered call sequences.

What if you were One Percent Better with Java inheritance?

  • You stop sweating multi-inheritance and blend behaviours like cocktails
  • You see method call sequences crystallise before your eyes
  • You cut duplicate code down to size with inheritance design patterns
  • You are a power user of inheritance keywords and modifiers
  • You lock-down specialist code to protect it from lesser developers
  • You feel the force of abstract class design at your fingertips

Java inheritance FAQ

Java inheritance FAQ ebook by Philip Shaw

ISBN
EPUB: 978-1-907863-02-8
Mobi: 978-1-907863-15-8

A guide to Java inheritance keywords, modifiers and design patterns. Covers multiple inheritance, method override, abstract classes and methods with inheritance pattern examples and extra related answers.

More about the Java inheritance ebook below

Buy now

Mobi for Amazon Kindle

EPUB for Apple iPad, Sony Reader, Nook

What's inside the Java inheritance ebook?

We keep standard publishing blurb to a minimum and put it at the back. The book starts with a brief introduction, then straight into:

  • 23 core Java inheritance questions and answers
  • 15 extra Java inheritance answers from other FAQs
  • Links for online updates

You get updates to this edition free by email.

Java inheritance ebook contents

The Java inheritance FAQ ebook helps you solve problems like these.

Multiple inheritance

Why doesn't Java support multiple inheritance?
Stop searching for syntax to extend two classes and learn how to do multiple inheritance in Java.
Doesn't implicit Object inheritance create multiple inheritance?
Some aspects of Java inheritance are not obvious so take time to understand implicit object inheritance.
Is multiple interface inheritance better than extending a class?
If your implementation classes are almost empty, you may be over-cooking multiple inheritance. Know when the extends keyword is good enough.
Can I achieve multiple inheritance without interfaces?
No matter how many abstract classes you write, you need to accept that multiple inheritance in Java needs an interface or two.

Java inheritance principles

What are the benefits of inheritance?
When you're a powerhouse with procedural languages your Java programs can be rather one dimensional, its time to step up to object oriented programming.
What forms of inheritance are supported by Java?
The simple mechanics of inheritance belies the sophisticated range of inheritance design patterns that can be created in the Java language.
Can you show examples of Java inheritance?
Progress from single class programs to layered Java applications when you extend a class.
Isn't specialization a form of inheritance?
Rich inheritance design patterns are built from simple Java language keywords.
What is the difference between abstract classes and inheritance?
Abstract classes have a special role in Java inheritance patterns, when you see how they fit in you'll be flying.
How does inheritance avoid duplication?
If your inheritance hierarchies only increase duplicate code, these pointers will show you where to look for savings.

Extending classes

What's the difference between importing and extending a class?
Move beyond copy and paste code and remove unnecessary import statements, you'll understand inheritance far better.
Can we explicitly inherit from the Object class?
Implicit object inheritance can confuse. Create clear class relationships with a better grasp of object inheritance.
How can I use inheritance in graphical user interfaces?
When you can't find a Swing component that does exactly what you need, be bold and create your own GUI extension.
How can I prevent a class from being extended?
If you're worried other programmers might break your code, a final class might be the best way to prevent inheritance.

Overridden methods

What is overriding?
Don't write lots of code to adapt standard Java classes, learn how to refine class behaviour by overriding methods and pass on the benefits.
Can an overridden method return void instead of an object?
Solve an “incompatible return type” problem with a better grasp of method override rules. It could remove pointless throw-away variables.
Why do overridden methods on a subclass have priority over the superclass?
It may be awkward sometimes but you need to follow a definite call sequence through overridden methods.
Can you give an example application that shows overriding?
The power of a good example will show you how to get different behaviour in subclasses by overriding methods.
How do you prevent a method from being overridden?
Other developers might break your finely-tuned method call sequence, have the final say and ensure your method always does the same thing.
How can I find the inherited attributes of a class?
This Java reflection example shows how to check class inheritance patterns at runtime.

Techniques for overridden superclasses

How can I call an overridden method in the superclass?
You don't need a superclass instance to call its methods, even when methods are overridden you can call superclass methods.
Can you give an example call to an overridden superclass method?
Unexpected behaviour when you call a superclass method? This example shows how to call an overridden superclass method and explains the call sequence.
How can I get the superclass to call back to a method in the subclass?
Build a superclass to call a set of subclasses that haven't been written yet with the template design pattern.

Extra Java inheritance questions

This ebook includes 15 extra Java inheritance-related answers from six other Java FAQs.

  • What's the use of concrete methods in abstract classes?
  • How many abstract subclasses can I create?
  • How can an abstract method be inherited?
  • Can you give an example of an abstract class?
  • Can you give an example of multiple inheritance with interfaces?
  • Can an interface extend a class?
  • Can an interface extend an abstract class?
  • How is the implements keyword different from extends?
  • Do interfaces have member variables?
  • Interface variables can be overridden, right?
  • What is dynamic method dispatch?
  • How can I prevent inheritance without marking a class final?
  • I assume inherited fields and members are non-private, are they?
  • What is an object in Java?
  • How do I create a Runnable with inheritance?

Any more questions?

Please contact us about the Java inheritance FAQ ebook.

One Percent Better ebook stockists

One Percent Better ebooks are stocked at Amazon in Mobi format for the Kindle, the Apple iBookstore and Google eBookstore in EPUB format.

Kindle editions at Amazon

One Percent Better ebooks are distributed through Amazon for direct download to your Kindle.

iPad ebooks at the iBookstore

One Percent Better ebooks are also distributed through the Apple iBookstore for direct download to your iPad.

EPUB editions at the Google eBookstore

One Percent Better ebooks are distributed through the Google eBookstore in EPUB format. Search for “Java inheritance FAQ”.

 

Ebooks for Web developers

More titles coming soon, contact us for news.